Class: Jirafe::Resource::Cart

Inherits:
LegacyResource show all
Includes:
DataHelper
Defined in:
lib/jirafe/resource/cart.rb

Instance Method Summary collapse

Methods included from DataHelper

#format_amount, #format_discount_amount

Methods inherited from LegacyResource

create, path, resource_url

Methods included from Model

#attributes, #create, included, #initialize, #reinitialize, #update

Methods included from Jirafe::ResponseParser

included

Instance Method Details

#attributes_for_change(key) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/jirafe/resource/cart.rb', line 13

def attributes_for_change(key)
  attrs = super
  attrs[:cid] = attrs.delete(:visitor_id)
  attrs[:idsite] = attrs.delete(:site_id)
  items = (attrs[:items] || []).map do |item|
    item.data
  end
  unless attrs[:revenue]
    attrs[:revenue] = attrs[:items].inject(0) do |sum, item|
      sum += item.price
      sum
    end
  end
  attrs[:revenue] = format_amount(attrs[:revenue])
  attrs[:ec_items] = items.to_json
  attrs.delete(:items)
  attrs.reject! {|k, v| v.nil? }
  attrs
end