Class: KitQtyAndCogsHandler
- Inherits:
-
Object
- Object
- KitQtyAndCogsHandler
- Defined in:
- app/subscribers/kit_qty_and_cogs_handler.rb
Overview
Sync subscriber for Events::KitComponentChanged.
Re-runs the cheap half of Item::KitConsolidator#consolidate_all_fields
inline: qty and COGS only. Product pages, inventory UI, and fulfillment
checks read these fields in the request cycle so they must be fresh
before the publishing transaction's caller returns.
The expensive half (consolidate_weights_and_dimensions, which calls
Item::ShippingBoxCalculator and is combinatorial in component count)
is owned by KitWeightsDimensionsHandler and runs async.
Subscribes to: Events::KitComponentChanged
Instance Method Summary collapse
Instance Method Details
#call(event) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/subscribers/kit_qty_and_cogs_handler.rb', line 21 def call(event) kit = Item.find_by(id: event.data[:kit_id]) # `:removed` swaps can leave a non-kit Item (last component gone), # and the kit row itself may have been destroyed in the same # transaction. Either way there's nothing to consolidate. return unless kit&.is_kit? Item::KitConsolidator.new(kit) .consolidate_qty .consolidate_unit_cogs .commit end |