Skip to content

41127 payment method sort order - #41144

Open
aasim110 wants to merge 5 commits into
magento:2.4-developfrom
aasim110:41127-payment-method-sort-order
Open

41127 payment method sort order#41144
aasim110 wants to merge 5 commits into
magento:2.4-developfrom
aasim110:41127-payment-method-sort-order

Conversation

@aasim110

Copy link
Copy Markdown
Contributor

Description

When a payment method becomes newly applicable during checkout (e.g. after the shipping country changes), its renderer was always appended to the end of the payment method list in the DOM — regardless of its configured sort_order. This caused payment methods to display out of order whenever the applicable list changed after the initial page render.

Root cause: the backend (Magento\Payment\Model\MethodList, Magento\Quote\Model\PaymentMethodManagement::getList) already returns payment methods correctly sorted by sort_order. The bug was in the frontend component Magento_Checkout/js/view/payment/list.js: when createRenderer() builds a renderer node for a newly-added payment method, it never set a sortOrder on the node. Magento_Ui's layout/collection insertion logic treats a missing sortOrder as "append to the end", so any method that became available after the initial render was always placed last, even if its sort_order was lower than methods already rendered.

Fix: createRenderer() now computes the method's current index within the already correctly-sorted paymentMethods() list and passes it through as the renderer node's sortOrder. This reuses the existing sortOrder-aware insertion mechanism already present in Magento_Ui/js/core/renderer/layout.js / collection.js, so a newly-added renderer is spliced into its correct position instead of always being appended. No backend/API changes are required.

Related Pull Requests

N/A

Fixed Issues (if relevant)

Fixes #41127

Manual testing scenarios

  1. Go to Stores > Configuration > Sales > Payment Methods.
  2. Set Check / Money Order: Sort Order = 10, Payment from Applicable Countries = All Allowed Countries.
  3. Set Cash On Delivery: Sort Order = 5, Payment from Applicable Countries = Specific CountriesGermany only.
  4. Save config.
  5. As a guest, add a product to the cart and go to checkout with shipping address country = United States — only Check/Money Order renders.
  6. On the shipping step, change the country to Germany and continue to the payment step.
  7. Before fix: Check/Money Order still renders above Cash On Delivery.
    After fix: Cash On Delivery (sort order 5) renders above Check/Money Order (sort order 10), matching their configured sort order.

Questions or comments

N/A

aasim110 added 5 commits June 15, 2026 14:09
…ith diagnostic message

When a module's menu.xml contains invalid declarations (e.g. a missing
'parent' attribute referencing a non-existent item, or missing required
params), the menu builder throws raw PHP exceptions (OutOfRangeException,
BadMethodCallException, InvalidArgumentException). These propagated
uncaught through the admin auth/redirect flow, causing ERR_TOO_MANY_REDIRECTS
with no visible error message and no log entry for the generic case.

Fix: All exception types caught in Menu\Config::getMenu() are now re-thrown
as LocalizedException with a developer-friendly diagnostic message that
includes the original error text and hints at the file/attribute to fix.
The original exception is preserved as getPrevious() for full stack traces.
The generic \Exception catch block now also logs via logger->critical().

Covered by updated unit tests in ConfigTest.
@m2-assistant

m2-assistant Bot commented Aug 24, 2026

Copy link
Copy Markdown

Hi @aasim110. Thank you for your contribution!
Here are some useful tips on how you can test your changes using Magento test environment.
❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names.

Allowed build names are:
  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here
ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.


For more details, review the Code Contributions documentation.
Join Magento Community Engineering Slack and ask your questions in #github channel.

@aasim110

Copy link
Copy Markdown
Contributor Author

@magento run all tests

@engcom-Hotel engcom-Hotel added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Aug 25, 2026
@github-project-automation github-project-automation Bot moved this to Pending Review in Pull Requests Dashboard Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: pending review

Projects

Status: Pending Review

Development

Successfully merging this pull request may close these issues.

Payment method renderer ignores sort order when added to checkout after initial page load

2 participants