requestshopwaresubscribershopware6

How to access request data in subscriber in shopware 6


I have built a subscriber in my plugin for Shopware 6 that subscribes to 'framework.validation.address.create' => 'onAddressCreation' event in order to add extra validation definition. But I also need to be able to access request data in the subscriber action.

How can I do that? So far I have managed to inject Shopware\Core\System\SystemConfig\SystemConfigService in the subscriber constructor and the subsriber action receives Shopware\Core\Framework\Validation\BuildValidationEvent but there is no way to get to the address fields with those two classes.


Solution

  • If you cannot pass the request from a controller or the request is not shipped with the event, you might want to inject the request_stack Symfony service https://symfony.com/doc/5.4/service_container/request.html