CartChangedEvent example

$this->eventDispatcher->dispatch(new BeforeLineItemRemovedEvent($lineItem$cart$context));

            $cart->markModified();
        }

        $cart = $this->cartCalculator->calculate($cart$context);
        $this->cartPersister->save($cart$context);

        $this->eventDispatcher->dispatch(new AfterLineItemRemovedEvent($lineItems$cart$context));

        $this->eventDispatcher->dispatch(new CartChangedEvent($cart$context));

        return new CartResponse($cart);
    }
}
/** @var array<mixed> $item */
        foreach ($itemsToUpdate as $item) {
            $this->lineItemFactory->update($cart$item$context);
        }

        $cart->markModified();

        $cart = $this->cartCalculator->calculate($cart$context);
        $this->cartPersister->save($cart$context);

        $this->eventDispatcher->dispatch(new AfterLineItemQuantityChangedEvent($cart$itemsToUpdate$context));
        $this->eventDispatcher->dispatch(new CartChangedEvent($cart$context));

        return new CartResponse($cart);
    }
}

    public function order(Cart $cart, SalesChannelContext $context, RequestDataBag $data): string
    {
        $orderId = $this->orderRoute->order($cart$context$data)->getOrder()->getId();

        if (isset($this->cart[$cart->getToken()])) {
            unset($this->cart[$cart->getToken()]);
        }

        $cart = $this->createNew($context->getToken());
        $this->eventDispatcher->dispatch(new CartChangedEvent($cart$context));

        return $orderId;
    }

    public function recalculate(Cart $cart, SalesChannelContext $context): Cart
    {
        $cart = $this->calculator->calculate($cart$context);
        $this->persister->save($cart$context);

        return $cart;
    }

    
$cart->add($item);

            $this->eventDispatcher->dispatch(new BeforeLineItemAddedEvent($item$cart$context$alreadyExists));
        }

        $cart->markModified();

        $cart = $this->cartCalculator->calculate($cart$context);
        $this->cartPersister->save($cart$context);

        $this->eventDispatcher->dispatch(new AfterLineItemAddedEvent($items$cart$context));
        $this->eventDispatcher->dispatch(new CartChangedEvent($cart$context));

        return new CartResponse($cart);
    }
}
Home | Imprint | This part of the site doesn't use cookies.