Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Réutilisation d'un même objet event dans plusieurs dispatch => problème si la propagation est stoppée. #77

Open
roadster31 opened this issue Oct 2, 2023 · 0 comments
Assignees

Comments

@roadster31
Copy link
Contributor

roadster31 commented Oct 2, 2023

Lorqu'un event est réutilisé pour faire plusieurs dispatch, par exemple pour réaliser une série d'actions, si la propagation est stoppée lors d'un des dispatch, les suivants ne seront pas réalisés.

Exemple dans CheckoutController, on utilise $orderEvent 3 fois de suite :

        $dispatcher->dispatch($orderEvent, TheliaEvents::ORDER_SET_DELIVERY_ADDRESS);
        $dispatcher->dispatch($orderEvent, TheliaEvents::ORDER_SET_POSTAGE);
        $dispatcher->dispatch($orderEvent, TheliaEvents::ORDER_SET_DELIVERY_MODULE);

Si dans l'action réalisé par ORDER_SET_POSTAGE la propagation est stoppée (par exemple ici : https://github.com/thelia/thelia/blob/a3519aa478c334e1b303a5e54f7a2b5c1dce341d/core/lib/Thelia/Action/Coupon.php#L259), alors ORDER_SET_DELIVERY_MODULE ne sera pas propagé.

Envoyr un clone $orderEvent plutôt qu'un $orderEvent résoud le problème, car seul l'objet event est cloné, les références à d'autres objets (ici l'Order) sont préservées, mais peut poser d'autres problèmes si les attributs de l'event sont modifiés mais doivent circuler.

Ou alors réinitialiser la propagation avant de re-dispatcher l'event ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants