Class: Spree::Stock::OrderCounter
- Inherits:
-
Object
- Object
- Spree::Stock::OrderCounter
- Defined in:
- app/models/spree/stock/order_counter.rb
Instance Attribute Summary collapse
-
#order ⇒ Object
readonly
Returns the value of attribute order.
Instance Method Summary collapse
- #assigned(variant) ⇒ Object
-
#initialize(order) ⇒ OrderCounter
constructor
A new instance of OrderCounter.
- #ordered(variant) ⇒ Object
- #remaining(variant) ⇒ Object
- #remaining? ⇒ Boolean
- #variants ⇒ Object
- #variants_with_remaining ⇒ Object
Constructor Details
#initialize(order) ⇒ OrderCounter
Returns a new instance of OrderCounter.
6 7 8 9 10 |
# File 'app/models/spree/stock/order_counter.rb', line 6 def initialize(order) @order = order @ordered_counts = count_line_items @assigned_counts = count_inventory_units end |
Instance Attribute Details
#order ⇒ Object (readonly)
Returns the value of attribute order
4 5 6 |
# File 'app/models/spree/stock/order_counter.rb', line 4 def order @order end |
Instance Method Details
#assigned(variant) ⇒ Object
28 29 30 |
# File 'app/models/spree/stock/order_counter.rb', line 28 def assigned(variant) @assigned_counts[variant] end |
#ordered(variant) ⇒ Object
24 25 26 |
# File 'app/models/spree/stock/order_counter.rb', line 24 def ordered(variant) @ordered_counts[variant] end |
#remaining(variant) ⇒ Object
32 33 34 |
# File 'app/models/spree/stock/order_counter.rb', line 32 def remaining(variant) @ordered_counts[variant] - @assigned_counts[variant] end |
#remaining? ⇒ Boolean
20 21 22 |
# File 'app/models/spree/stock/order_counter.rb', line 20 def remaining? not variants_with_remaining.empty? end |
#variants ⇒ Object
12 13 14 |
# File 'app/models/spree/stock/order_counter.rb', line 12 def variants @ordered_counts.keys end |
#variants_with_remaining ⇒ Object
16 17 18 |
# File 'app/models/spree/stock/order_counter.rb', line 16 def variants_with_remaining variants.select { |variant| remaining(variant) > 0 } end |