Sha256: 81d1186d0a899b8803487486f5621be99df635470c0470c9c99d746d163eb5d9

Contents?: true

Size: 980 Bytes

Versions: 1

Compression:

Stored size: 980 Bytes

Contents

module Spree
  module TrackersHelper
    def product_for_segment(product, optional = {})
      {
        product_id: product.id,
        sku: product.sku,
        category: product.category.try(:name),
        name: product.name,
        brand: product.brand.try(:name),
        price: product.price.to_f,
        currency: product.currency,
        url: product_url(product),
      }.tap do |hash|
        # This method returns either asset_url (Paperclip) or rails_blob_path (ActiveStorage) to return the specified image(s)
        if defined?(ActiveStorage) && !Rails.application.config.use_paperclip
          hash[:image_url] =  request.base_url + Rails.application.routes.url_helpers.rails_blob_path(optional.delete(:image).attachment, only_path: true) if optional[:image]
        else
          hash[:image_url] = request.base_url + asset_url(optional.delete(:image).attachment) if optional[:image]
        end
      end.merge(optional).to_json.html_safe
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spree_analytics_trackers-1.0.1 app/helpers/spree/trackers_helper.rb