Class: SpreeKlaviyo::OrderPresenter

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

Direct Known Subclasses

ShipmentPresenter

Instance Method Summary collapse

Constructor Details

#initialize(order:) ⇒ OrderPresenter

Returns a new instance of OrderPresenter.



6
7
8
9
10
# File 'app/presenters/spree_klaviyo/order_presenter.rb', line 6

def initialize(order:)
  @order = order
  @current_store = order.store
  @products = products(order)
end

Instance Method Details

#callObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/presenters/spree_klaviyo/order_presenter.rb', line 12

def call
  {
    email: @order&.user&.email || @order.email,
    customer_name: @order.name || ::Spree.t('customer'),
    store_name: @current_store.name,
    order_id: @order.number,
    order_number: @order.number,
    affiliation: @order.store.name,
    value: subtotal,
    subtotal: subtotal,
    item_total: @order.item_total&.to_f,
    total: @order.total.to_f,
    revenue: @order.total&.to_f,
    shipping: @order.shipments.sum(&:cost).to_f,
    shipping_method: shipping_method_names,
    tax: @order.additional_tax_total&.to_f,
    included_tax: @order.included_tax_total&.to_f,
    discount: @order.promo_total&.to_f,
    items: products(@order),
    coupon: @order.coupon_code.to_s,
    currency: @order.currency,
    completed_at: @order.completed_at&.iso8601.to_s,
    checkout_url: ::Spree::Core::Engine.routes.url_helpers.checkout_url(host: @current_store.url_or_custom_domain, token: @order.token),
    all_adjustments: all_adjustments,
    bill_address: AddressPresenter.new(address: @order.bill_address).call,
    ship_address: AddressPresenter.new(address: @order.ship_address).call
  }.merge(try_shipped_shipments)
end