Class: Workarea::Order::Item
- Inherits:
-
Object
- Object
- Workarea::Order::Item
- Includes:
- ApplicationDocument
- Defined in:
- app/models/workarea/order/item.rb
Instance Method Summary collapse
-
#adjust_pricing(options = {}) ⇒ self
Adds a price adjustment to the item.
-
#current_unit_price ⇒ Money
The unit price of the item including all currently attached price adjustments.
-
#customizations ⇒ Hash
Customizations to the item, beyond what the variant options were.
-
#customizations_eql?(test) ⇒ Boolean
Determine whether the customizations of this item are equivalent to the customizations of another.
-
#customized? ⇒ Boolean
Whether this item has any customizations.
-
#digital? ⇒ Boolean
Whether this item is a digital (not-shipped) type of item.
-
#matches_categories?(*ids) ⇒ Boolean
Whether the item is in any of the category ids passed.
-
#matches_products?(*ids) ⇒ Boolean
Whether the item is for any of the product ids passed.
-
#on_sale? ⇒ Boolean
Whether this item is on sale (as of the last time the order was priced).
-
#original_unit_price ⇒ Money
The base price per-unit for this item.
Methods included from ApplicationDocument
Methods included from Sidekiq::Callbacks
assert_valid_config!, async, disable, enable, inline, #run_callbacks
Instance Method Details
#adjust_pricing(options = {}) ⇒ self
Adds a price adjustment to the item. Does not persist.
44 45 46 |
# File 'app/models/workarea/order/item.rb', line 44 def adjust_pricing( = {}) price_adjustments.build() end |
#current_unit_price ⇒ Money
The unit price of the item including all currently attached price adjustments.
84 85 86 87 |
# File 'app/models/workarea/order/item.rb', line 84 def current_unit_price return 0.to_m if price_adjustments.blank? price_adjustments.adjusting('item').sum.to_m / quantity end |
#customizations ⇒ Hash
Customizations to the item, beyond what the variant options were. Examples would include engraving, monogramming, etc. This should be a sanitized hash that has passed through the Catalog::Customizations system.
107 108 109 |
# File 'app/models/workarea/order/item.rb', line 107 def customizations super || {} end |
#customizations_eql?(test) ⇒ Boolean
Determine whether the customizations of this item are equivalent to the customizations of another. This is used when updating/adding items so we can see whether we should merge items that have the same SKU but different customizations.
128 129 130 131 132 133 134 135 136 137 |
# File 'app/models/workarea/order/item.rb', line 128 def customizations_eql?(test) if test.present? && customizations.present? test.inject(true) do |memo, tuple| key, value = *tuple memo && customizations[key].to_s == value.to_s end else test.blank? && customizations.blank? end end |
#customized? ⇒ Boolean
Whether this item has any customizations.
115 116 117 |
# File 'app/models/workarea/order/item.rb', line 115 def customized? customizations.present? end |
#digital? ⇒ Boolean
Whether this item is a digital (not-shipped) type of item.
36 37 38 |
# File 'app/models/workarea/order/item.rb', line 36 def digital? !!product_attributes['digital'] end |
#matches_categories?(*ids) ⇒ Boolean
Whether the item is in any of the category ids passed. Used in discount qualification.
54 55 56 57 |
# File 'app/models/workarea/order/item.rb', line 54 def matches_categories?(*ids) match_ids = Array(ids).flatten.map(&:to_s) (category_ids.map(&:to_s) & match_ids).any? end |
#matches_products?(*ids) ⇒ Boolean
Whether the item is for any of the product ids passed. Used in discount qualification.
65 66 67 68 |
# File 'app/models/workarea/order/item.rb', line 65 def matches_products?(*ids) match_ids = Array(ids).flatten.map(&:to_s) product_id.to_s.in?(match_ids) end |
#on_sale? ⇒ Boolean
Whether this item is on sale (as of the last time the order was priced).
94 95 96 97 |
# File 'app/models/workarea/order/item.rb', line 94 def on_sale? return false if price_adjustments.blank? !!price_adjustments.first.data['on_sale'] end |
#original_unit_price ⇒ Money
The base price per-unit for this item.
74 75 76 77 |
# File 'app/models/workarea/order/item.rb', line 74 def original_unit_price return 0.to_m if price_adjustments.blank? price_adjustments.first.unit.to_m end |