Class: Shipping::ItemKitExploder
- Inherits:
-
Object
- Object
- Shipping::ItemKitExploder
- Defined in:
- app/services/shipping/item_kit_exploder.rb
Defined Under Namespace
Classes: Result
Class Method Summary collapse
Class Method Details
.item_to_hash(item, quantity, result) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/services/shipping/item_kit_exploder.rb', line 20 def self.item_to_hash(item, quantity, result) qty = quantity.to_i.abs if item.is_kit? result.kit_item_ids << item.id item.kit_target_item_relations.order(:target_item_id).each do |tir| item_key = tir.target_item_id result.full_item_id_hash[item_key] ||= 0 result.full_item_id_hash[item_key] += (qty * tir.quantity.to_i) end else item_key = item.id result.full_item_id_hash[item_key] ||= 0 result.full_item_id_hash[item_key] += qty end result end |
.process(item_hash) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'app/services/shipping/item_kit_exploder.rb', line 10 def self.process(item_hash) r = Result.new item_hash.each do |item, quantity| item_to_hash(item, quantity, r) end # Sort item id in order r.full_item_id_hash = Hash[r.full_item_id_hash.sort] r end |