Class: Events::KitComponentChanged

Inherits:
ApplicationEvent show all
Defined in:
app/events/events.rb

Overview

Domain event emitted when an ItemRelation of relation_type=Kit Component
is added, removed, swapped, or has its quantity changed. Replaces the
synchronous after_commit :consolidate_kit callback that ran
KitConsolidator#consolidate_all_fields per-row inline — that path
cascaded into consolidate_weights_and_dimensions
ShippingBoxCalculator#fitting_rotation which is combinatorial in the
component count and can take 100s of seconds per kit for cable-system
kits with many components (incident: UDG4-4999-WY cutover #921).

Two subscribers handle different parts of the cascade:

  • KitQtyAndCogsHandler (sync POROl) — runs qty + COGS consolidation
    because product pages, inventory UI, and fulfillment checks need
    these fresh in the request cycle.
  • KitWeightsDimensionsHandler (async ApplicationJob) — runs the
    combinatorial weight/box recompute. Short-circuits when the swap's
    old and new components are physically identical (same shipping
    dimensions and weights), which is the common case for a
    branded → unbranded substitution like UDG4-WY → UDG.

reason is informational — both handlers run for every reason — but
carries enough metadata to skip the expensive recompute in the dims
handler when no shipping change is possible.

Payload:
kit_id: Integer — source_item_id (the kit Item)
target_item_id: Integer — current target component (after the change)
prior_target_id: Integer, nil — set on "swapped" only
reason: String — "added" | "removed" | "swapped" | "qty_changed"

See Also:

Method Summary

Methods inherited from ApplicationEvent

#data