Shopware 6 get cart in page

36 Views Asked by At

i want to get the current cart when the product page is loaded.

public function onProductPageLoadedEvent(ProductPageLoadedEvent $event) {
    $cart = ... get cart here
}

i have implemented the CartService already, but i need a token.

1

There are 1 best solutions below

0
Talentix On

The token is part of the SalesChannelContext. You can get the customer's cart like this:

public function onProductPageLoadedEvent(ProductPageLoadedEvent $event) {
    $cart = $this->cartService->getCart($event->getSalesChannelContext()->getToken(), $event->getSalesChannelContext());
}