Class: Workarea::MailChimp::Cart

Inherits:
Object
  • Object
show all
Includes:
I18n::DefaultUrlOptions
Defined in:
app/services/workarea/mail_chimp/cart.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(order, options = {}) ⇒ Cart

Returns a new instance of Cart.



9
10
11
12
# File 'app/services/workarea/mail_chimp/cart.rb', line 9

def initialize(order, options = {})
  @order = order
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'app/services/workarea/mail_chimp/cart.rb', line 7

def options
  @options
end

#orderObject (readonly)

Returns the value of attribute order.



7
8
9
# File 'app/services/workarea/mail_chimp/cart.rb', line 7

def order
  @order
end

Instance Method Details

#to_hObject

Returns Hash.

Returns:

  • Hash



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/services/workarea/mail_chimp/cart.rb', line 15

def to_h
  cart_hsh = {
    id: order.id.to_s,
    currency_code: order.total_price.currency.iso_code,
    order_total: order.total_price.to_s,
    tax_total: order.tax_total.to_s,
    shipping_total: order.shipping_total.to_s,
    lines: lines,
    customer: customer,
    checkout_url: Storefront::Engine.routes.url_helpers.resume_cart_url(token: order.token, host: Workarea.config.host),
  }

  # Mailchimp api does not accept empty values for campaign ID
  # only merge in if the campaign ID is present
  cart_hsh.merge!(campaign_id: order.mail_chimp_campaign_id) if order.mail_chimp_campaign_id.present?

  cart_hsh
end