Skip to content

Refactoring order thank you controller#18782

Merged
NoResponseMate merged 2 commits intoSylius:new-routingfrom
loic425:refactoring-order-thank-you
Feb 24, 2026
Merged

Refactoring order thank you controller#18782
NoResponseMate merged 2 commits intoSylius:new-routingfrom
loic425:refactoring-order-thank-you

Conversation

@loic425
Copy link
Copy Markdown
Member

@loic425 loic425 commented Feb 3, 2026

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

The idea is to remove the ResourceController usage.
Indead, we will deprecate the ResourceController after closing this issue #18212.

Summary by CodeRabbit

  • Documentation

    • Added upgrade guide with before/after examples and step‑by‑step migration instructions for the order thank-you route.
  • Deprecations

    • Legacy thank-you action marked deprecated with guidance for updating integrations.
  • Refactor

    • Thank-you page moved to a new service-backed controller; route definition simplified and behavior preserved (redirects when no order in session, renders the thank-you template when present).

@loic425 loic425 requested review from a team as code owners February 3, 2026 15:18
@probot-autolabeler probot-autolabeler bot added Maintenance CI configurations, READMEs, releases, etc. Shop ShopBundle related issues and PRs. labels Feb 3, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 3, 2026

📝 Walkthrough

Walkthrough

Refactors the shop thank-you flow by adding an invokable controller service OrderThankYouAction, switching the sylius_shop_order_thank_you route to reference that service, registering the service, and marking the legacy OrderController::thankYouAction as deprecated; docs updated with upgrade guidance.

Changes

Cohort / File(s) Summary
Documentation
UPGRADE-2.3.md
Adds migration guidance and before/after YAML showing route change from defaults-based _controller/_sylius.template to a direct controller service reference.
Deprecation Marking
src/Sylius/Bundle/CoreBundle/Controller/OrderController.php
Adds a deprecation docblock and runtime deprecation trigger inside thankYouAction (signature unchanged).
New Controller Implementation
src/Sylius/Bundle/ShopBundle/Controller/OrderThankYouAction.php
Adds final invokable controller that reads sylius_order_id from session, looks up the order, removes session key, renders default or provided template with order, or redirects to homepage if missing/not found.
Routing & Service Configuration
src/Sylius/Bundle/ShopBundle/Resources/config/routing/order.yml, src/Sylius/Bundle/ShopBundle/Resources/config/services/controller.xml
Route sylius_shop_order_thank_you now uses controller: sylius_shop.controller.order_thank_you; new service sylius_shop.controller.order_thank_you registered with Twig, order repository, and router arguments and controller.service_arguments tag.

Sequence Diagram

sequenceDiagram
    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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • GSadee
  • Rafikooo

Poem

🐰 I hopped in to tidy the thank-you track,

A tiny service now carries the pack.
Session key cleared, the order takes flight,
Twig stitches pages in gentle moonlight.
🥕 Hooray — one small hop, and everything's right.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Refactoring order thank you controller' accurately summarizes the main change: the order thank you controller has been refactored from using ResourceController to a dedicated OrderThankYouAction class.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 3, 2026

❌ Preview Environment deleted from Bunnyshell

Available commands:

  • 🚀 /bns:deploy to redeploy the environment

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 @see reference and runtime trigger.

The docblock deprecation is good, but for better developer experience:

  1. Add a @see tag pointing to the replacement (OrderThankYouController)
  2. 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 as readonly.

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 empty defaults: block.

The defaults: block on line 8 appears to be empty (line 9 is blank). Since the controller: 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:

@loic425 loic425 force-pushed the refactoring-order-thank-you branch 2 times, most recently from 4bd05c7 to 5fe795b Compare February 3, 2026 15:44
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@loic425 loic425 force-pushed the refactoring-order-thank-you branch from 5fe795b to 531989c Compare February 4, 2026 07:53
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 @deprecated docblock 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's trigger_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.

@loic425 loic425 force-pushed the refactoring-order-thank-you branch from 42ee7c6 to d9c5148 Compare February 4, 2026 09:04
@loic425 loic425 marked this pull request as draft February 23, 2026 15:43
@loic425 loic425 force-pushed the refactoring-order-thank-you branch from d9c5148 to 3923297 Compare February 23, 2026 16:16
@probot-autolabeler probot-autolabeler bot added the Admin AdminBundle related issues and PRs. label Feb 23, 2026
@loic425 loic425 changed the base branch from 2.3 to new-routing February 23, 2026 16:16
@loic425 loic425 marked this pull request as ready for review February 23, 2026 16:17
@NoResponseMate NoResponseMate merged commit d0c8a4d into Sylius:new-routing Feb 24, 2026
29 of 36 checks passed
@loic425 loic425 deleted the refactoring-order-thank-you branch February 24, 2026 08:32
NoResponseMate added a commit that referenced this pull request Feb 24, 2026
| 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 -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Admin AdminBundle related issues and PRs. Maintenance CI configurations, READMEs, releases, etc. Shop ShopBundle related issues and PRs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants