warma2dwarma2d MemberComments: 1 Received thanks: 0 Member since: September 2019

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 :)

Answers

  • Michael TelgmannMichael Telgmann AdministratorsComments: 1344 Received thanks: 385 Member since: June 2014

    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

  • warma2dwarma2d MemberComments: 1 Received thanks: 0 Member since: September 2019

    I use CheckoutCartPageLoadedEvent::class=>'getFastorderProduts'

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

    problem solved :)

  • Michael TelgmannMichael Telgmann AdministratorsComments: 1344 Received thanks: 385 Member since: June 2014

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

    Thanked by 1warma2d
  • HansibertHansibert MemberComments: 7 Received thanks: 1 Member since: June 2016

    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

Sign In or Register to comment.