return new StockAlteration($id,
$productId,
$qtyBefore,
$newQty);
} /**
* @return array<string>
*/
private function getAffectedIds(EntityWriteEvent
$event): array
{ return array_map( static fn (WriteCommand
$command) =>
$command->
getPrimaryKey()['id'
],
array_filter($event->
getCommandsForEntity(OrderLineItemDefinition::ENTITY_NAME
),
static function DWriteCommand
$command) { if ($command instanceof DeleteCommand ||
$command instanceof InsertCommand
) { return true;
} if ($command->
hasField('referenced_id'
) ||
$command->
hasField('product_id'
) ||
$command->
hasField('quantity'
)) { return true;
} return false;
}) );
}