Sha256: 41c390cd15a662174ee9e0d6da744e94d1c29c13fabc0b34d608a73b750d85f1

Contents?: true

Size: 1.04 KB

Versions: 4

Compression:

Stored size: 1.04 KB

Contents

module SpreeAnalyticsTrackers
  module Segment
    class ProductPresenter < SpreeAnalyticsTrackers::BasePresenter
      private

      def serialize_resource(resource, options = {})
        {
          resource_id: resource.id.to_s,
          sku: resource.sku&.to_s,
          category: resource.category&.name,
          name: resource.name,
          brand: brand_name,
          price: resource.price_in(current_currency).amount&.to_f,
          currency: current_currency,
          url: resource_url(resource)
        }.tap do |hash|
          hash[:image_url] = segment_image_url(hash, options)
        end.merge(options)
      end

      def segment_image_url(hash, options)
        
      end

      def brand_name
        resource.vendor.name if defined?(SpreeMultiVendor) && resource.defined?(:vendor) && resource.vendor.present?
        
        resource.brand&.name
      end

      def current_currency
        @current_currency ||= options[:current_currency]
      end

      def locale
        @locale ||= options[:locale]
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
spree_analytics_trackers-2.1.1 app/presenters/spree_analytics_trackers/segment/product_presenter.rb
spree_analytics_trackers-2.1.0 app/presenters/spree_analytics_trackers/segment/product_presenter.rb
spree_analytics_trackers-2.0.0 app/presenters/spree_analytics_trackers/segment/product_presenter.rb
spree_analytics_trackers-2.0.0.rc1 app/presenters/spree_analytics_trackers/segment/product_presenter.rb