Class: SpreeKlaviyo::ProductPresenter

Inherits:
Object
  • Object
show all
Includes:
Spree::BaseHelper, Spree::ImagesHelper
Defined in:
app/presenters/spree_klaviyo/product_presenter.rb

Direct Known Subclasses

LineItemPresenter

Instance Method Summary collapse

Constructor Details

#initialize(product:, store:) ⇒ ProductPresenter

Returns a new instance of ProductPresenter.



7
8
9
10
11
# File 'app/presenters/spree_klaviyo/product_presenter.rb', line 7

def initialize(product:, store:)
  @product = product
  @current_store = store
  @current_currency = store.default_currency
end

Instance Method Details

#callObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/presenters/spree_klaviyo/product_presenter.rb', line 13

def call
  return {} if @product.nil?

  {
    name: @product.name,
    price: @product.amount_in(current_currency)&.to_f,
    brand: @product&.brand_name,
    category: @product.main_taxon&.pretty_name,
    currency: current_currency,
    url: spree_storefront_resource_url(@product, store: @store),
    image_url: @product.default_image.present? ? spree_image_url(@product.default_image, width: 1200, height: 1200, format: :png) : '',
    sku: @product.sku
  }
end