Refactoring order thank you controller#18782
Refactoring order thank you controller#18782NoResponseMate merged 2 commits intoSylius:new-routingfrom
Conversation
📝 WalkthroughWalkthroughRefactors the shop thank-you flow by adding an invokable controller service Changes
Sequence DiagramsequenceDiagram
participant Client
participant Router
participant OrderThankYouAction
participant Session
participant OrderRepository
participant Twig
participant Response
Client->>Router: GET /order/thank-you
Router->>OrderThankYouAction: __invoke(Request, ?template)
OrderThankYouAction->>Session: get('sylius_order_id')
alt order id present
OrderThankYouAction->>OrderRepository: find(orderId)
alt order found
OrderThankYouAction->>Session: remove('sylius_order_id')
OrderThankYouAction->>Twig: render(template, {order})
Twig-->>OrderThankYouAction: rendered HTML
OrderThankYouAction-->>Response: 200 HTML
Response-->>Client: 200 Thank You Page
else order not found
OrderThankYouAction-->>Response: 302 Redirect to homepage
Response-->>Client: 302 Redirect
end
else no order id
OrderThankYouAction-->>Response: 302 Redirect to homepage
Response-->>Client: 302 Redirect
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
❌ Preview Environment deleted from BunnyshellAvailable commands:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/Sylius/Bundle/ShopBundle/Controller/OrderThankYouController.php`:
- Line 36: Replace the hard-coded session key 'sylius_order_id' with the class
constant to ensure consistency; change the call that retrieves the order id from
$request->getSession()->get('sylius_order_id', null) to use self::ORDER_ID_PARAM
so the $orderId assignment and subsequent logic (e.g. usages of $orderId and
references to ORDER_ID_PARAM) consistently rely on the defined constant.
🧹 Nitpick comments (3)
src/Sylius/Bundle/CoreBundle/Controller/OrderController.php (1)
62-62: Consider enhancing the deprecation notice with a@seereference and runtime trigger.The docblock deprecation is good, but for better developer experience:
- Add a
@seetag pointing to the replacement (OrderThankYouController)- Consider triggering a runtime deprecation notice so developers are alerted during execution
♻️ Suggested enhancement
- /** `@deprecated` This method is deprecated and will be removed in Sylius 3.0 */ + /** + * `@deprecated` since Sylius 2.3, will be removed in Sylius 3.0. Use {`@see` \Sylius\Bundle\ShopBundle\Controller\OrderThankYouController} instead. + */ public function thankYouAction(Request $request): Response { + trigger_deprecation( + 'sylius/sylius', + '2.3', + 'The "%s::thankYouAction()" method is deprecated and will be removed in Sylius 3.0. Use "%s" instead.', + self::class, + \Sylius\Bundle\ShopBundle\Controller\OrderThankYouController::class, + ); + $configuration = $this->requestConfigurationFactory->create($this->metadata, $request);src/Sylius/Bundle/ShopBundle/Controller/OrderThankYouController.php (1)
27-31: Consider marking constructor properties asreadonly.Per coding guidelines, immutable services should use
readonly. Since these dependencies are injected once and never modified, marking them as readonly provides additional safety.♻️ Suggested enhancement
public function __construct( - private Environment $twig, - private OrderRepositoryInterface $orderRepository, - private RouterInterface $router, + private readonly Environment $twig, + private readonly OrderRepositoryInterface $orderRepository, + private readonly RouterInterface $router, ) { }src/Sylius/Bundle/ShopBundle/Resources/config/routing/order.yml (1)
7-9: Remove the emptydefaults:block.The
defaults:block on line 8 appears to be empty (line 9 is blank). Since thecontroller:key already sets the controller and no other defaults are needed, the empty block should be removed for cleaner configuration.♻️ Suggested cleanup
sylius_shop_order_thank_you: path: /thank-you methods: [GET] controller: sylius_shop.controller.order_thank_you - defaults: sylius_shop_order_pay:
src/Sylius/Bundle/ShopBundle/Controller/OrderThankYouController.php
Outdated
Show resolved
Hide resolved
4bd05c7 to
5fe795b
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/Sylius/Bundle/ShopBundle/Resources/config/routing/order.yml`:
- Around line 4-9: The route definition for sylius_shop_order_thank_you contains
an empty defaults: key which parses as null and breaks Route::addDefaults();
remove the empty defaults: line entirely or replace it with an explicit empty
mapping (defaults: {}) in the routing entry so Route::addDefaults() receives an
array; update the sylius_shop_order_thank_you route block accordingly.
5fe795b to
531989c
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/Sylius/Bundle/ShopBundle/Controller/OrderThankYouAction.php`:
- Around line 42-47: Move the session removal so the order ID isn't discarded
before verification: currently the call to
$request->getSession()->remove(self::ORDER_ID_PARAM) executes before
$this->orderRepository->findOrderById($orderId); change the flow to first call
$this->orderRepository->findOrderById($orderId) and only remove
self::ORDER_ID_PARAM from the session after confirming $order is not null (i.e.,
after the existence check using findOrderById and before returning the success
response), leaving the
RedirectResponse($this->router->generate('sylius_shop_homepage')) path untouched
when order is null.
🧹 Nitpick comments (1)
src/Sylius/Bundle/CoreBundle/Controller/OrderController.php (1)
62-63: Consider adding a runtime deprecation trigger.The
@deprecateddocblock is good for IDE hints, but won't warn developers at runtime. Consider triggering a deprecation notice at the start of the method body using Symfony'strigger_deprecation()function:/** `@deprecated` This method is deprecated and will be removed in Sylius 3.0 */ public function thankYouAction(Request $request): Response { + trigger_deprecation( + 'sylius/sylius', + '2.3', + 'The "%s" method is deprecated and will be removed in Sylius 3.0. Use "%s" instead.', + __METHOD__, + OrderThankYouAction::class, + ); + $configuration = $this->requestConfigurationFactory->create($this->metadata, $request);This requires adding the
use function Symfony\Component\Deprecation\trigger_deprecation;import.
42ee7c6 to
d9c5148
Compare
d9c5148 to
3923297
Compare
| Q | A |-----------------|----- | Branch? | 2.3 | Bug fix? | no | New feature? | yes | BC breaks? | yes (but an easy one) | Deprecations? | no | Related tickets | partially #18212 | License | MIT <!-- - Bug fixes must be submitted against the 1.14 or 2.1 branch - Features and deprecations must be submitted against the 2.2 branch - Make sure that the correct base branch is set To be sure you are not breaking any Backward Compatibilities, check the documentation: https://docs.sylius.com/en/latest/book/organization/backward-compatibility-promise.html --> Based on #18782 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Documentation** * Added upgrade guide for v2.3 route configuration changes with migration instructions for customized routes. * **Deprecation** * Legacy controller methods marked for removal in v3.0. * **Chores** * Updated route handling structure and refactored controller implementations for improved architecture. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
The idea is to remove the ResourceController usage.
Indead, we will deprecate the ResourceController after closing this issue #18212.
Summary by CodeRabbit
Documentation
Deprecations
Refactor