Magento2: Allmethods config source model does not always report the full list of payment methods

Created on 1 Feb 2018  路  8Comments  路  Source: magento/magento2

The Magento\Payment\Model\Config\Source\Allmethods config source model does not display every available payment method.

Preconditions

  1. Magento version 2.1.11, plain fresh installation

Steps to reproduce

  1. Enable the Cash on Delivery payment method
  2. Define a config field like this:
<field id="test" type="multiselect">
    <label>Test case for displaying all payment methods</label>
    <source_model>Magento\Payment\Model\Config\Source\Allmethods</source_model>
</field>
  1. Load the config field in the Magento backend

Expected result

  1. The enabled Cash on Delivery payment method should be visible in the config field multiselect

Actual result

  1. The Cash On Delivery payment method is not listed in the widget

Comments

I have tracked the source of the issue down to the app/code/Magento/Payment/Helper/Data.php::getPaymentMethodList() method, which does not report the full list of payment methods when $asLabelValue = true and $withGroups = true.

The issue was apparently introduced with this commit, which does not consider that a group's $labelValues[$code]['value'] might already hold payment method information:

$labelValues[$code]['value'] = null;

This is the issue for that pull request:

And this is the issue that prompted the problematic pull request:

Fixed in 2.2.x Fixed in 2.3.x Confirmed Format is valid Ready for Work Reproduced on 2.1.x

All 8 comments

@moehrenzahn, thank you for your report.
We've acknowledged the issue and added to our backlog.

@moehrenzahn The issue is already fixed in 2.2.
Closing ticket for now. Please reopen if you need any further assistance with this.

@magento-engcom-team What are the commits for this issue?

I want to note that this issue is definitively still reproducible on 2.2.4. @magento-engcom-team, can you please check this.
(I am not able to reopen this issue, but please consider it reopened.)

@magento-engcom-team
We also could reproduce the issue on 2.2.4. This malfunction happens only when $withGroups is true.
When adding the group, the mentioned line of code "$labelValues[$code]['value'] = null;" causes the already set method values to be overridden. Due to sorting the array alphabetically first, the group "offline" e.g. overrides four already set values such as "checkmo".

A quick fix would be to only set the value if it doesn't already exist (fixed in src/vendor/magento/module-payment/Helper/Data.php lines 296-298)

if (!isset($labelValues[$code]['value'])) {
$labelValues[$code]['value'] = null;
}

Hi @moehrenzahn. Thank you for your report.
The issue has been fixed in magento/magento2#15032 by @mash1t in 2.2-develop branch
Related commit(s):

The fix will be available with the upcoming 2.2.5 release.

Hi @moehrenzahn. Thank you for your report.
The issue has been fixed in magento/magento2#15134 by @mzeis in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.0 release.

FYI it will be released in 2.2.6 we see that the PR is merged only in this version

Was this page helpful?
0 / 5 - 0 ratings