Class: Workarea::Order::Item

Inherits:
Object
  • Object
show all
Includes:
ApplicationDocument
Defined in:
app/models/workarea/order/item.rb

Instance Method Summary collapse

Methods included from ApplicationDocument

#releasable?

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

#embedded_children

Instance Method Details

#adjust_pricing(options = {}) ⇒ self

Adds a price adjustment to the item. Does not persist.

Returns:

  • (self)


75
76
77
# File 'app/models/workarea/order/item.rb', line 75

def adjust_pricing(options = {})
  price_adjustments.build(options)
end

#current_unit_priceMoney

The unit price of the item including all currently attached price adjustments.

Returns:



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

#customizationsHash

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.

Returns:

  • (Hash)


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.

Parameters:

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


63
64
65
# File 'app/models/workarea/order/item.rb', line 63

def digital?
  !!product_attributes['digital']
end

#download?Boolean

Returns:

  • (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.

Parameters:

Returns:

  • (Boolean)


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.

Parameters:

  • ids (Array)

Returns:

  • (Boolean)


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.

Parameters:

  • ids (Array)

Returns:

  • (Boolean)


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).

Returns:

  • (Boolean)


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_priceMoney

The base price per-unit for this item.

Returns:



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

Returns:

  • (Boolean)


41
42
43
# File 'app/models/workarea/order/item.rb', line 41

def shipping?
  fulfillment == 'shipping'
end