Class: Spree::OrderContents
- Inherits:
-
Object
- Object
- Spree::OrderContents
- Defined in:
- app/models/spree/order_contents.rb
Instance Attribute Summary collapse
-
#currency ⇒ Object
Returns the value of attribute currency.
-
#order ⇒ Object
Returns the value of attribute order.
Instance Method Summary collapse
- #add(variant, quantity = 1, options = {}) ⇒ Object
-
#initialize(order) ⇒ OrderContents
constructor
A new instance of OrderContents.
- #remove(variant, quantity = 1, options = {}) ⇒ Object
- #remove_line_item(line_item, options = {}) ⇒ Object
- #update_cart(params) ⇒ Object
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
#currency ⇒ Object
Returns the value of attribute currency.
3 4 5 |
# File 'app/models/spree/order_contents.rb', line 3 def currency @currency end |
#order ⇒ Object
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 13 14 |
# File 'app/models/spree/order_contents.rb', line 9 def add(variant, quantity = 1, = {}) = Time.current line_item = add_to_line_item(variant, quantity, ) [:line_item_created] = true if <= line_item.created_at after_add_or_remove(line_item, ) end |
#remove(variant, quantity = 1, options = {}) ⇒ Object
16 17 18 19 |
# File 'app/models/spree/order_contents.rb', line 16 def remove(variant, quantity = 1, = {}) line_item = remove_from_line_item(variant, quantity, ) after_add_or_remove(line_item, ) end |
#remove_line_item(line_item, options = {}) ⇒ Object
21 22 23 24 |
# File 'app/models/spree/order_contents.rb', line 21 def remove_line_item(line_item, = {}) line_item.destroy! after_add_or_remove(line_item, ) end |
#update_cart(params) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/models/spree/order_contents.rb', line 26 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. persist_totals PromotionHandler::Cart.new(order).activate order.ensure_updated_shipments persist_totals true else false end end |