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 = 1, options = {}) ⇒ Object


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

def add(variant, quantity = 1, options = {})
  line_item = add_to_line_item(variant, quantity, options)
  after_add_or_remove(line_item, options)
end

#remove(variant, quantity = 1, options = {}) ⇒ Object


14
15
16
17
# File 'app/models/spree/order_contents.rb', line 14

def remove(variant, quantity = 1, options = {})
  line_item = remove_from_line_item(variant, quantity, options)
  after_add_or_remove(line_item, options)
end

#update_cart(params) ⇒ Object


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/models/spree/order_contents.rb', line 19

def update_cart(params)
  if order.update_attributes(filter_order_items(params))
    order.line_items = order.line_items.select { |li| li.quantity > 0 }
    # Update totals, then check if the order is eligible for any cart promotions.
    # If we do not update first, then the item total will be wrong and ItemTotal
    # promotion rules would not be triggered.
    reload_totals
    PromotionHandler::Cart.new(order).activate
    order.ensure_updated_shipments
    reload_totals
    true
  else
    false
  end
end