Class: Spree::SimpleOrderContents
- Inherits:
-
Object
- Object
- Spree::SimpleOrderContents
- Defined in:
- app/models/spree/simple_order_contents.rb
Instance Attribute Summary collapse
-
#order ⇒ Object
Returns the value of attribute order.
Instance Method Summary collapse
-
#add(variant, quantity = 1, options = {}) ⇒ Spree::LineItem
Add a line items to the order if there is inventory to do so and populate Promotions.
- #advance ⇒ Object
- #approve(user: nil, name: nil) ⇒ Object
-
#initialize(order) ⇒ SimpleOrderContents
constructor
A new instance of SimpleOrderContents.
- #remove(variant, quantity = 1, options = {}) ⇒ Object
- #remove_line_item(line_item, options = {}) ⇒ Object
- #update_cart(params) ⇒ Object
Constructor Details
#initialize(order) ⇒ SimpleOrderContents
Returns a new instance of SimpleOrderContents.
7 8 9 |
# File 'app/models/spree/simple_order_contents.rb', line 7 def initialize(order) @order = order end |
Instance Attribute Details
#order ⇒ Object
Returns the value of attribute order.
5 6 7 |
# File 'app/models/spree/simple_order_contents.rb', line 5 def order @order end |
Instance Method Details
#add(variant, quantity = 1, options = {}) ⇒ Spree::LineItem
Add a line items to the order if there is inventory to do so and populate Promotions
22 23 24 25 |
# File 'app/models/spree/simple_order_contents.rb', line 22 def add(variant, quantity = 1, = {}) line_item = add_to_line_item(variant, quantity, ) after_add_or_remove(line_item, ) end |
#advance ⇒ Object
50 51 52 |
# File 'app/models/spree/simple_order_contents.rb', line 50 def advance while @order.next; end end |
#approve(user: nil, name: nil) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/models/spree/simple_order_contents.rb', line 54 def approve(user: nil, name: nil) if user.blank? && name.blank? raise ArgumentError, 'user or name must be specified' end order.update!( approver: user, approver_name: name, approved_at: Time.current ) end |
#remove(variant, quantity = 1, options = {}) ⇒ Object
27 28 29 30 |
# File 'app/models/spree/simple_order_contents.rb', line 27 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
32 33 34 35 |
# File 'app/models/spree/simple_order_contents.rb', line 32 def remove_line_item(line_item, = {}) order.line_items.destroy(line_item) after_add_or_remove(line_item, ) end |
#update_cart(params) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/models/spree/simple_order_contents.rb', line 37 def update_cart(params) if order.update(params) unless order.completed? order.line_items = order.line_items.select { |li| li.quantity > 0 } order.check_shipments_and_restart_checkout end reload_totals true else false end end |