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

Returns a new instance of 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, currency = nil, shipment = nil) ⇒ Object



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

def add(variant, quantity, currency=nil, shipment=nil)
  #get current line item for variant if exists
  line_item = order.find_line_item_by_variant(variant)

  #add variant qty to line_item
  add_to_line_item(line_item, variant, quantity, currency, shipment)
end

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



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

def remove(variant, quantity, shipment=nil)
  #get current line item for variant
  line_item = order.find_line_item_by_variant(variant)

  #TODO raise exception if line_item is nil

  #remove variant qty from line_item
  remove_from_line_item(line_item, variant, quantity, shipment)
end