How to get cart token in Subscriber ?

Hello!

In my controller I got cartToken something like this.

public function myfunc( SalesChannelContext $context )
{
  $cartToken = $context->getToken();
}

However, I can’t do it the same way in the subscriber, as I don’t know how to insert SalesChannelContext into services.xml

Therefore, my question is the following: how to get a cartToken in the subscriber myfunc ?

Tell me please :slight_smile:

Hello,

if you have the SalesChannelContext available depends on the event you are subscribing to. You can not inject it via the services.xml
Which event do you use?

Best regards from Schöppingen

cool Michael Telgmann

I use CheckoutCartPageLoadedEvent::class=>‚getFastorderProduts‘

In the end, I did something like this: $cartToken = $event->getSalesChannelContext()->getToken();

problem solved :slight_smile:

yes, this is the right way for Subscriber  Thumb-Up

1 Like

Hello

How do we get the current customer, cart, billing/shipping addresses/methods etc if the event does not provide a SalesChannelContext (but only a Shopware\Core\Framework\Context)? In situations when this data is defined (e.g. during the processing of a request in the checkout) there must be a way to access it. But how?

Thanks

@Hansibert Did you find a solution?
I have the same problem, I am using the CheckoutOrderPlacedEvent and need to get the token of the cart the order was created from. If the CheckoutOrderPlacedEvent would contain the SalesChannelContext all would be good. But in the CartOrderRoute’s order function only the base context is passed. Why is that and is there a way to get the whole SalesChannelContext and therefore the cart token?

Help would be very appreciated!