Change matching method in ShopContextSubscriber#39837
Conversation
|
Hi @djbuch, [Edit] |
|
Hello, I made the change you said, let's wait and see the check results. [Edit] |
Okay, even though I tested it quickly locally and it works, let's wait for the tests to be sure/safe |
|
Yes the PHPStan tests failed Error: Call to an undefined method Symfony\Component\Routing\RouterInterface::matchRequest(). Line src/PrestaShopBundle/EventListener/Admin/Context/ShopContextSubscriber.php 365 Call to an undefined method |
|
@djbuch You could try it this way: PrestaShop/app/config/admin/services.yml Line 61 in 8ab6eb7 you can replace PrestaShopBundle\EventListener\Admin\Context\ShopContextSubscriber: ~ with:
PrestaShopBundle\EventListener\Admin\Context\ShopContextSubscriber:
autowire: true
autoconfigure: true
arguments:
$router: '@router'Let's check if it doesn't throw an error anymore, and then we'll ask the others for confirmation too. |
|
Hello I checked the problem, and the code below helped: Could you guys check? |
|
@kpodemski where should this code go ? |
|
I haven't tested other bugs that were reported by @Codencode, I've only tested sending emails :) If that works, then it also requires removing RouterInterface and adapting tests if needed |
|
But the problem here is in the matching of the route. Because of "request.isXmlHttpRequest()" in the route definition. |
|
@djbuch I'm not sure about that, to me the problem was a mismatch in the route. After applying the changes I don't have any errors mentioned by @Codencode |
@kpodemski this solution works, I tested it for the cases that were causing issues and it's ok. |
|
@kpodemski yes but the missmatch is because of But the route exists, it is defined so it should be found. You can see that if you remove the condition [EDIT] : Did you try it in multishop context ? |
Of course, it worked for me w/o multistore enabled. It didn't after enabling multi-store, it showed me that the URL doesn't exist. |
|
OK and are you shure that with your code the good shop context is loaded ? |
|
@djbuch checking |
|
@djbuch I'm testing sending emails, I've set a different data in the single and all stores context, I managed to correctly receive the email for the corresponding inboxes |
|
And what if you don't send this through XmlHttpRequest ? Because the whole this is about this condition in route definition. If it is not needed for security reasons, then we could remove it from the conditions. |
If we remove it from the route definition, we then have to add the check in the controller method. This was the solution I thought of, which you can find here: #39991 |
|
Yes but with my solution the condition works |
|
@Codencode it is always false because ->match($request->getPathInfo()) will recreate a mocked request with the info about XmlHttpRequest missing, but with ->matchRequest($request) it works |
Ah ok, I didn't realize it was in addition to your solution. |
|
ok, thanks for the info let's ping @jolelievre to see his opinion as well, not relying on the interface is not a clean way, but on the other hand, creating an adapter like some RouterMatcher is probably too much |
|
Well, I've checked, and route conditions in rhe route listener are checked before our subscriber, so when I do the POST directly, it shows me:
When I remove the condition: It returns me JSON response :) |
| private readonly ShopConfigurationInterface $configuration, | ||
| private readonly MultistoreFeature $multistoreFeature, | ||
| private readonly RouterInterface $router, | ||
| private readonly Router $router, |
There was a problem hiding this comment.
I think you should be able to replace this with RequestMatcherInterface the interface that implements the method you need. And the @router service correctly implements it
As much as possible we should favor using interfaces instead of explicit classes
There was a problem hiding this comment.
Hello I already tried that : 4228f42 but the check failed
There was a problem hiding this comment.
Ok tried again and with forcing the argument this time, let's see
| PrestaShopBundle\EventListener\Admin\Context\ShopContextSubscriber: | ||
| autowire: true | ||
| autoconfigure: true | ||
| arguments: | ||
| $router: '@router' |
There was a problem hiding this comment.
The autowire and autoconfigure are already set as default values on this file (at the top of the file), so in theory you don't need to change this service definition
The autowiring should also be able to automatically inject the @router service (also check my other comment about using the appropriate interface) If by lack of chance the DI doesn't inject the service you expect to you can at most limit this modifications to only the arguments part
There was a problem hiding this comment.
@jolelievre
Hi Jonathan,
If we don't pass the $router: '@router' parameter to the service, we get this error:
Cannot autowire service "PrestaShopBundle\EventListener\Admin\Context\ShopContextSubscriber": argument
"$router" of method "__construct()" references class "Symfony\Component\Routing\Router" but no such service exists.
Try changing the type-hint to one of its parents: interface "Symfony\Component\Routing\RouterInterface", interface
"Symfony\Component\Routing\RequestContextAwareInterface", interface "Symfony\Component\Routing\Generator\UrlGeneratorInterface",
or interface "Symfony\Component\Routing\Matcher\UrlMatcherInterface".
So apparently, the system can't inject Symfony\Component\Routing\Router, which is why I suggested modifying the service definition.
You're absolutely right that we can avoid re-adding autowire and autoconfigure - I was the one who led @djbuch to make that mistake.
There was a problem hiding this comment.
Hello, tried without, and I need the arguments part. But as it is written for some other Services forcing arguments in the file I think I should keep
autowire: true
autoconfigure: true
There was a problem hiding this comment.
ok my bad, let's go with then
|
since the PR was stuck on rebase for a while, I went ahead and did it myself. |
|
@kpodemski @jolelievre I ran the test and the PR works correctly. We're now waiting for the UI tests that were created from scratch because I performed the rebase, and obviously the second approval is still missing. c/c @SiraDIOP screen-capture.webm |
|
UI TEST are green 🟢 https://github.com/Codencode/ga.tests.ui.pr/actions/runs/26416354197 |
|
thank you @djbuch @Codencode |
|
Thanks @Codencode, sorry I didn't find the time to rebase.
Cordialement,
David-Julian BUCH, Direction technique et financière Sites internet -
Applications mobiles - Cloud entreprise - ERP CRM
[image: Logo Web Premiere] <https://www.web-premiere.fr/> +33(0)5 63 79 22
06 <0563792206> ***@***.*** www.web-premiere.fr
Ce message et les fichiers qui y sont éventuellement joints sont
exclusivement réservés au destinataire. Il peut contenir des données ou des
informations confidentielles ou protégées par la loi. Si vous n'êtes pas le
destinataire de ce message, merci de le détruire. Veuillez imprimer ce mail
qu'en cas de nécessité. Réduisons ensemble le gaspillage et la pollution
inutile. Web Premiere s'engage au quotidient en utilisant des serveurs
équipés des dernières technologies de pointes, plus économes en énergie
basés à 100% en France pour une meilleure protection de vos données.
*🗓 Prendre rendez-vous avec moi
<https://www.calendly.com/david-web-premiere/>*
*🆕 Suivez l'activité de Web Premiere sur notre Blog
<https://www.web-premiere.fr/les-actualites-de-lagence-web-premiere/> | ✏️
Découvrez nos dernières réalisations
<https://www.web-premiere.fr/nos-realisations-sites-internet-applications-mobiles/>*
*✅ Prélèvement bancaire automatique* : Simplifiez le règlement de vos
abonnements en activant le prélèvement automatique depuis votre espace
client <https://pro.web-premiere.fr/> rubrique *"Mandat"*
*➡ Accéder à votre espace client <https://pro.web-premiere.fr/>*
Le mar. 26 mai 2026 à 11:15, Krystian Podemski ***@***.***> a
écrit :
… *kpodemski* left a comment (PrestaShop/PrestaShop#39837)
<#39837 (comment)>
thank you @djbuch <https://github.com/djbuch> @Codencode
<https://github.com/Codencode>
—
Reply to this email directly, view it on GitHub
<#39837?email_source=notifications&email_token=ABLAMXEA3ZP3PP7G6AFYMKT44VOELA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTINJUGI3DONJXGM3KM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#issuecomment-4542675736>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABLAMXDOVTHNJHV4T5S4EFL44VOELAVCNFSM6AAAAACKHPQVNOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHM2DKNBSGY3TKNZTGY>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|


match()instead ofmatchRequest()caused the full Request object not to be passed to the router. This resulted inSymfony\Component\Routing\Matcher\Dumper\CompiledUrlMatcherTraitgenerating a "pseudo" request without headers, breaking route conditions that rely on request properties (e.g.,request.isXmlHttpRequest()on theadmin_emails_send_testroute).2. Try to send a test email using the AJAX request
3. Verify that the request is properly handled and the
isXmlHttpRequest()condition is correctly evaluated4. Check that routes with request-based conditions (like header checks) work as expected