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 15 16 |
# File 'app/models/spree/order_contents.rb', line 9 def add(variant, quantity = 1, = {}) = Time.current ActiveRecord::Base.transaction do line_item = add_to_line_item(variant, quantity, ) [:line_item_created] = true if <= line_item.created_at after_add_or_remove(line_item, ) end end |
#remove(variant, quantity = 1, options = {}) ⇒ Object
18 19 20 21 22 23 |
# File 'app/models/spree/order_contents.rb', line 18 def remove(variant, quantity = 1, = {}) ActiveRecord::Base.transaction do line_item = remove_from_line_item(variant, quantity, ) after_add_or_remove(line_item, ) end end |
#remove_line_item(line_item, options = {}) ⇒ Object
25 26 27 28 29 30 |
# File 'app/models/spree/order_contents.rb', line 25 def remove_line_item(line_item, = {}) ActiveRecord::Base.transaction do line_item.destroy! after_add_or_remove(line_item, ) end end |
#update_cart(params) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/models/spree/order_contents.rb', line 32 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. ActiveRecord::Base.transaction do persist_totals PromotionHandler::Cart.new(order).activate order.ensure_updated_shipments order.payments.store_credits.checkout.destroy_all persist_totals end true else false end end |