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.
- #download? ⇒ Boolean
-
#fulfilled_by?(*types) ⇒ Boolean
Whether this order has any items that need to be fulfilled by a particular fulfillment policy.
-
#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.
-
#shipping? ⇒ Boolean
These methods exist for findability.
Methods included from ApplicationDocument
Methods included from Sidekiq::Callbacks
add_worker, assert_valid_config!, async, caching_classes?, disable, enable, inline, #run_callbacks, workers, workers_list
Methods included from Mongoid::Document
Instance Method Details
#adjust_pricing(options = {}) ⇒ self
Adds a price adjustment to the item. Does not persist.
75 76 77 |
# File 'app/models/workarea/order/item.rb', line 75 def adjust_pricing( = {}) price_adjustments.build() end |
#current_unit_price ⇒ Money
The unit price of the item including all currently attached price adjustments.
115 116 117 118 |
# File 'app/models/workarea/order/item.rb', line 115 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.
138 139 140 |
# File 'app/models/workarea/order/item.rb', line 138 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.
159 160 161 162 163 164 165 166 167 168 |
# File 'app/models/workarea/order/item.rb', line 159 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.
146 147 148 |
# File 'app/models/workarea/order/item.rb', line 146 def customized? customizations.present? end |
#digital? ⇒ Boolean
Whether this item is a digital (not-shipped) type of item.
63 64 65 |
# File 'app/models/workarea/order/item.rb', line 63 def digital? !!product_attributes['digital'] end |
#download? ⇒ Boolean
45 46 47 |
# File 'app/models/workarea/order/item.rb', line 45 def download? fulfillment == 'download' end |
#fulfilled_by?(*types) ⇒ Boolean
Whether this order has any items that need to be fulfilled by a particular fulfillment policy.
55 56 57 |
# File 'app/models/workarea/order/item.rb', line 55 def fulfilled_by?(*types) types.any? { |t| send("#{t}?") } end |
#matches_categories?(*ids) ⇒ Boolean
Whether the item is in any of the category ids passed. Used in discount qualification.
85 86 87 88 |
# File 'app/models/workarea/order/item.rb', line 85 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.
96 97 98 99 |
# File 'app/models/workarea/order/item.rb', line 96 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).
125 126 127 128 |
# File 'app/models/workarea/order/item.rb', line 125 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.
105 106 107 108 |
# File 'app/models/workarea/order/item.rb', line 105 def original_unit_price return 0.to_m if price_adjustments.blank? price_adjustments.first.unit.to_m end |
#shipping? ⇒ Boolean
These methods exist for findability
41 42 43 |
# File 'app/models/workarea/order/item.rb', line 41 def shipping? fulfillment == 'shipping' end |