calculateChanges example



        $beforeLineItems = $this->fetchOrderLineItems($ids);
        $context = $event->getContext();

        $event->addSuccess(function D) use ($ids$beforeLineItems$context): void {
            $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);
        });
    }
Home | Imprint | This part of the site doesn't use cookies.