$afterLineItems =
$this->
fetchOrderLineItems($ids);
$changes =
[];
foreach ($beforeLineItems as $id =>
$lineItem) { $changes =
[...
$changes, ...
$this->
calculateChanges($id,
$lineItem,
$afterLineItems[$id] ?? null
)];
} foreach ($afterLineItems as $id =>
$lineItem) { // this item was added, decrease the stock
if (!
isset($beforeLineItems[$id])) { $changes[] =
$this->
changeset($id,
$lineItem['referenced_id'
], 0,
(int) $lineItem['quantity'
]);
} } $this->stockStorage->
alter($changes,
$context);
});
} public function stateChanged(StateMachineTransitionEvent
$event): void
{ if (!
$this->
isEnabled()) { return;
}