# How to get cart token in Subscriber ?

**URL:** https://forum.shopware.com/t/how-to-get-cart-token-in-subscriber/61809
**Category:** General Questions (EN)
**Created:** [17. September 2019 um 10:11 UTC](https://forum.shopware.com/t/how-to-get-cart-token-in-subscriber/61809 "2019-09-17T10:11:12Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![warma2d](https://avatars.discourse-cdn.com/v4/letter/w/f17d59/32.png) [@warma2d](https://forum.shopware.com/u/warma2d)
#### Post date: [17. September 2019 um 10:11 UTC](https://forum.shopware.com/t/how-to-get-cart-token-in-subscriber/61809/1 "2019-09-17T10:11:12Z")

</div>

Hello!

In my controller I got cartToken something like this.

public function myfunc( SalesChannelContext $context )  
{  
&nbsp; $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 🙂

---

<div class="post-metadata">

### Author: ![Michael\_Telgmann](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/michael_telgmann/32/20289_2.png) [@Michael\_Telgmann](https://forum.shopware.com/u/Michael_Telgmann)
#### Post date: [17. September 2019 um 11:41 UTC](https://forum.shopware.com/t/how-to-get-cart-token-in-subscriber/61809/2 "2019-09-17T11:41:35Z")

</div>

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](http://forum.shopware.com/plugins/CKEditor/plugins/smiley/images/shopware.png "cool")&nbsp;Michael Telgmann

---

<div class="post-metadata">

### Author: ![warma2d](https://avatars.discourse-cdn.com/v4/letter/w/f17d59/32.png) [@warma2d](https://forum.shopware.com/u/warma2d)
#### Post date: [17. September 2019 um 13:15 UTC](https://forum.shopware.com/t/how-to-get-cart-token-in-subscriber/61809/3 "2019-09-17T13:15:43Z")

</div>

I use&nbsp;CheckoutCartPageLoadedEvent::class=\>‚getFastorderProduts‘

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

problem solved 🙂

---

<div class="post-metadata">

### Author: ![Michael\_Telgmann](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/michael_telgmann/32/20289_2.png) [@Michael\_Telgmann](https://forum.shopware.com/u/Michael_Telgmann)
#### Post date: [17. September 2019 um 14:09 UTC](https://forum.shopware.com/t/how-to-get-cart-token-in-subscriber/61809/4 "2019-09-17T14:09:41Z")

</div>

yes, this is the right way for Subscriber&nbsp; ![Thumb-Up](https://forum.shopware.com/plugins/CKEditor/plugins/smiley/images/thumb-up.png "Thumb-Up")

---

<div class="post-metadata">

### Author: ![Hansibert](https://avatars.discourse-cdn.com/v4/letter/h/8e8cbc/32.png) [@Hansibert](https://forum.shopware.com/u/Hansibert)
#### Post date: [27. Juni 2020 um 10:34 UTC](https://forum.shopware.com/t/how-to-get-cart-token-in-subscriber/61809/5 "2020-06-27T10:34:34Z")

</div>

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

---

<div class="post-metadata">

### Author: ![nick](https://avatars.discourse-cdn.com/v4/letter/n/f9ae1b/32.png) [@nick](https://forum.shopware.com/u/nick)
#### Post date: [10. Juni 2021 um 13:49 UTC](https://forum.shopware.com/t/how-to-get-cart-token-in-subscriber/61809/6 "2021-06-10T13:49:02Z")

</div>

@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!
