Skip to content

Commit 158582a

Browse files
committed
Use helper method that doesn't throw when no model
When a payment configuration node exists in XML but there is no <model> defined, getList() will throw an UnexpectedValueException. One use case for creating such a set-up is a module that provides default configuration overrides for payment methods which are not installed on the current website. For example: <config> <default> <payment> <checkmo> <active>0</active> </checkmo> <not_installed_here> <debug>0</debug> <environment>production</environment> </not_installed_here> </payment> </default> </config> In this case, the payment method 'not_installed_here' does not have a <model> node defined, as the payment method module is not installed on the website.
1 parent ed3f42b commit 158582a

File tree

1 file changed

+1
-15
lines changed

1 file changed

+1
-15
lines changed

app/code/Magento/Payment/Model/PaymentMethodList.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,12 @@ public function __construct(
3939
*/
4040
public function getList($storeId)
4141
{
42-
$methodsCodes = array_keys($this->helper->getPaymentMethods());
43-
44-
$methodsInstances = array_map(
45-
function ($code) {
46-
return $this->helper->getMethodInstance($code);
47-
},
48-
$methodsCodes
49-
);
42+
$methodsInstances = $this->helper->getStoreMethods($storeId);
5043

5144
$methodsInstances = array_filter($methodsInstances, function (MethodInterface $method) {
5245
return !($method instanceof \Magento\Payment\Model\Method\Substitution);
5346
});
5447

55-
@uasort(
56-
$methodsInstances,
57-
function (MethodInterface $a, MethodInterface $b) use ($storeId) {
58-
return (int)$a->getConfigData('sort_order', $storeId) - (int)$b->getConfigData('sort_order', $storeId);
59-
}
60-
);
61-
6248
$methodList = array_map(
6349
function (MethodInterface $methodInstance) use ($storeId) {
6450

0 commit comments

Comments
 (0)