# Kein SalesChannelContext im MailSentEvent

**URL:** <https://forum.shopware.com/t/kein-saleschannelcontext-im-mailsentevent/101485>\
**Category:** Programmierung\
**Tags:** programming\
**Created:** [6. Oktober 2023 um 07:45 UTC](https://forum.shopware.com/t/kein-saleschannelcontext-im-mailsentevent/101485 "2023-10-06T07:45:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ansgar](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/ansgar/32/7871_2.png) [@ansgar](https://forum.shopware.com/u/ansgar)\
**Post date:** [6. Oktober 2023 um 07:45 UTC](https://forum.shopware.com/t/kein-saleschannelcontext-im-mailsentevent/101485/1 "2023-10-06T07:45:59Z")

</div>

Es gibt scheinbar einige subscriber-fähige Events bei denen kein `$event->getSalesChannelContext()` implementiert ist, um an den aktuellen SalesChannelContext zu bekommen. Z.B. `MailSentEvent::class` und auch `KernelEvents::EXCEPTION`. Wenn man in solchen Subscribern den aktuellen SalesChannel benötigt, frage ich diesen bisher umständlich ab:

```auto
        /** @var SalesChannelRepository $salesChannelRepository */
        $salesChannelRepository = $this->container->get('sales_channel.repository');
        $criteria = new Criteria();
        $criteria->addFilter(new ContainsFilter('domains.url', $_SERVER['HTTP_HOST']));
        $salesChannels = $salesChannelRepository->search($criteria, Context::createDefaultContext());
        $currentSalesChannel = $salesChannels->count() > 0 ? $salesChannels->first() : null;

```

Geht das auch mit weniger Code bzw. einfacher?

---

<div class="post-metadata">

**Author:** ![chamaw](https://avatars.discourse-cdn.com/v4/letter/c/b487fb/32.png) [@chamaw](https://forum.shopware.com/u/chamaw)\
**Post date:** [7. Oktober 2023 um 04:48 UTC](https://forum.shopware.com/t/kein-saleschannelcontext-im-mailsentevent/101485/2 "2023-10-07T04:48:16Z")

</div>

Ich würde mal vermute die Mail-Funktion kommt direkt aus Symfony und letztlich hast Du halt keine direkte Bindung an den SalesContext. Und Deine Funktion wird halt auch nicht bei einem Aufruf über die Console (= Command) funktionieren …
