Home > Blockchain >  Shopware 6 Saving Affiliate/Campaign code to session at anytime I enter the shop
Shopware 6 Saving Affiliate/Campaign code to session at anytime I enter the shop

Time:10-21

I'm on a Production System 6.4.2.1, but had the same problem on a newer version 6.4.14

If you enter the shop for the first time with a query parameter URL for example https://shop/?affiliateCode=test&campaignCode=test, the codes will not be saved to the session to use it for example in the cart or have this flags on an order (which is standard shopware function).

After you entered the shop you have to navigate to another page than paste in the url with query parameter to get it saved to the session.

If you than delete your site data and enter the shop again with this query parameter url its not working again.

This issue happens only in production if cache is turned on. As far as I could investigate this issue I noticed that for the very first time symfony fires the "BeforeSendResponseEvent" which Shopware listens to but this just terminates the first request with our query parameters So now if you navigate to another page and enter the url with query parameter again, than Symfony will trigger the KernelEvent which Shopware listens to to add the query parameters to the session.

Did anyone else had trouble with this issue before?

CodePudding user response:

Yeah, I think you got it right. Looking at the listener the corresponding event isn't dispatched if the http cache is hit. The affiliate and campaign parameters become part of the cache key and therefore consecutive requests will result in cache hits, avoiding the listener.

I think your best bet might be to create a ticket on the issue tracker. Ultimately this will need to be fixed in the codebase.

For now the only way to be sure the codes are stored in the sessions would be to publicize URLs with the parameters on routes that aren't http cached, like /account/register. For workarounds you could register your own controller that avoids the http cache and redirects to the home page, just for the sake of not missing these parameters. Another option would be to listen to to HttpCacheHitEvent as described here and set the codes to the session yourself, even though you might also have to start the session at that point.

  • Related