Skip to content
Advertisement

shopware6 – inject data in profile page or route http://domain/account/*

In Shopware6, I want to write a controller for the route http://domain/account/*. Only I have to write in eventListener or is there other possibility? I also could not find events for this url (http://domain/account/address).

This is my current way, but this is not enough.

File : {moduleOneSubscriber.php}

public static function getSubscribedEvents(): array
{
    return [
        AccountLoginPageLoadedEvent::class => 'myFunctionName',
        CheckoutRegisterPageLoadedEvent::class => 'myFunctionName',
        AccountProfilePageLoadedEvent::class => 'myFunctionName',
        AccountOverviewPageLoadedEvent::class => 'myFunctionName',
        AccountPaymentMethodPageLoadedEvent::class => 'myFunctionName',
        AccountOrderPageLoadedEvent::class => 'myFunctionName',
    ];
}

Advertisement

Answer

There does not seem to be a generic event only for all account/* pages, so the approach you are doing is basically correct: Collect all the events for all the account pages.

You can for example use the Symfony profiler toolbar and search in the event tab in all tree tabs for PageLoaded Events.

So you just might add the events mentioned by Valerii in the comments.

Event tabs

Another approach would be to subscribe ShopwareStorefrontPageGenericPageLoadedEvent and check the pathInfo of the request passed to the event, whether you are on account.

if (!str_starts_with($event->getRequest()->getPathInfo(), '/account/') {
   return;
);

// do your thing

This has the advantage that if new pages are added later with the same path, you do not need to add additional events.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement