Class: Portage::Ucp::Cart

Inherits:
Data
  • Object
show all
Defined in:
lib/portage/ucp/value_objects.rb

Overview

schemas/shopping/cart.json — requires ucp/id/line_items/currency/totals. The "ucp" envelope is added centrally by Portage::Ucp::WireEnvelope, not stored on the value object itself. discounts is the dev.ucp.shopping.discount extension (optional on both cart.json and its own schema) — omitted from the wire payload when empty, same as Order#adjustments.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, line_items:, currency:, totals:, discounts: Discounts.new) ⇒ Cart

Returns a new instance of Cart.



382
# File 'lib/portage/ucp/value_objects.rb', line 382

def initialize(id:, line_items:, currency:, totals:, discounts: Discounts.new) = super

Instance Attribute Details

#currencyObject (readonly)

Returns the value of attribute currency

Returns:

  • (Object)

    the current value of currency



381
382
383
# File 'lib/portage/ucp/value_objects.rb', line 381

def currency
  @currency
end

#discountsObject (readonly)

Returns the value of attribute discounts

Returns:

  • (Object)

    the current value of discounts



381
382
383
# File 'lib/portage/ucp/value_objects.rb', line 381

def discounts
  @discounts
end

#idObject (readonly)

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



381
382
383
# File 'lib/portage/ucp/value_objects.rb', line 381

def id
  @id
end

#line_itemsObject (readonly)

Returns the value of attribute line_items

Returns:

  • (Object)

    the current value of line_items



381
382
383
# File 'lib/portage/ucp/value_objects.rb', line 381

def line_items
  @line_items
end

#totalsObject (readonly)

Returns the value of attribute totals

Returns:

  • (Object)

    the current value of totals



381
382
383
# File 'lib/portage/ucp/value_objects.rb', line 381

def totals
  @totals
end

Instance Method Details

#to_wire_hObject



384
385
386
387
388
389
# File 'lib/portage/ucp/value_objects.rb', line 384

def to_wire_h
  h = { "id" => id, "line_items" => line_items.map(&:to_wire_h), "currency" => currency,
        "totals" => totals.map(&:to_wire_h) }
  h["discounts"] = discounts.to_wire_h unless discounts.empty?
  h
end