Class: Spree::OrderContents

Inherits:
Object
  • Object
show all
Defined in:
app/models/spree/order_contents.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(order) ⇒ OrderContents


5
6
7
# File 'app/models/spree/order_contents.rb', line 5

def initialize(order)
  @order = order
end

Instance Attribute Details

#currencyObject

Returns the value of attribute currency


3
4
5
# File 'app/models/spree/order_contents.rb', line 3

def currency
  @currency
end

#orderObject

Returns the value of attribute order


3
4
5
# File 'app/models/spree/order_contents.rb', line 3

def order
  @order
end

Instance Method Details

#add(variant, quantity = 1, currency = nil, shipment = nil) ⇒ Object

Get current line item for variant if exists Add variant qty to line_item


11
12
13
14
# File 'app/models/spree/order_contents.rb', line 11

def add(variant, quantity = 1, currency = nil, shipment = nil)
  line_item = order.find_line_item_by_variant(variant)
  add_to_line_item(line_item, variant, quantity, currency, shipment)
end

#remove(variant, quantity = 1, shipment = nil) ⇒ Object

Get current line item for variant Remove variant qty from line_item


18
19
20
21
22
23
24
25
26
# File 'app/models/spree/order_contents.rb', line 18

def remove(variant, quantity = 1, shipment = nil)
  line_item = order.find_line_item_by_variant(variant)

  unless line_item
    raise ActiveRecord::RecordNotFound, "Line item not found for variant #{variant.sku}"
  end

  remove_from_line_item(line_item, variant, quantity, shipment)
end