Skip to content

Commit 0644f24

Browse files
MAGETWO-60351: Unnecessary disabled payment methods on checkout page #4868
1 parent 79f392c commit 0644f24

File tree

4 files changed

+29
-22
lines changed

4 files changed

+29
-22
lines changed

app/code/Magento/Payment/Plugin/PaymentConfigurationProcess.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,9 @@ public function beforeProcess(\Magento\Checkout\Block\Checkout\LayoutProcessor $
5959
$activePaymentMethodCodes = array_map($getCodeFunc, $activePaymentMethodList);
6060

6161
foreach ($configuration as $paymentGroup => $groupConfig) {
62-
foreach (array_keys($groupConfig['methods']) as $paymentCode) {
63-
if (!in_array($paymentCode, $activePaymentMethodCodes)) {
64-
unset($configuration[$paymentGroup]['methods'][$paymentCode]);
65-
}
62+
$notActivePaymentMethodCodes = array_diff(array_keys($groupConfig['methods']), $activePaymentMethodCodes);
63+
foreach ($notActivePaymentMethodCodes as $notActivePaymentMethodCode) {
64+
unset($configuration[$paymentGroup]['methods'][$notActivePaymentMethodCode]);
6665
}
6766
if (empty($configuration[$paymentGroup]['methods'])) {
6867
unset($configuration[$paymentGroup]);

app/code/Magento/Payment/Test/Unit/Plugin/PaymentConfigurationProcessTest.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,23 @@ public function testBeforeProcess($jsLayout, $activePaymentList, $expectedResult
9898
public function beforeProcessDataProvider()
9999
{
100100
$jsLayout['components']['checkout']['children']['steps']['children']['billing-step']
101+
['children']['payment']['children']['renders']['children'] = [
102+
'braintree' => [
103+
'methods' => [
104+
'braintree_paypal' => [],
105+
'braintree' => []
106+
]
107+
],
108+
'paypal-payments' => [
109+
'methods' => [
110+
'payflowpro' => [],
111+
'payflow_link' => []
112+
]
113+
]
114+
];
115+
$result1['components']['checkout']['children']['steps']['children']['billing-step']
116+
['children']['payment']['children']['renders']['children'] = [];
117+
$result2['components']['checkout']['children']['steps']['children']['billing-step']
101118
['children']['payment']['children']['renders']['children'] = [
102119
'braintree' => [
103120
'methods' => [
@@ -106,8 +123,6 @@ public function beforeProcessDataProvider()
106123
]
107124
]
108125
];
109-
$result['components']['checkout']['children']['steps']['children']['billing-step']
110-
['children']['payment']['children']['renders']['children'] = [];
111126

112127
$braintreePaymentMethod = $this
113128
->getMockBuilder(\Magento\Payment\Api\Data\PaymentMethodInterface::class)
@@ -124,8 +139,8 @@ public function beforeProcessDataProvider()
124139
$braintreePaypalPaymentMethod->expects($this->any())->method('getCode')->willReturn('braintree_paypal');
125140

126141
return [
127-
[$jsLayout, [], $result],
128-
[$jsLayout, [$braintreePaymentMethod, $braintreePaypalPaymentMethod], $jsLayout]
142+
[$jsLayout, [], $result1],
143+
[$jsLayout, [$braintreePaymentMethod, $braintreePaypalPaymentMethod], $result2]
129144
];
130145
}
131146
}

app/code/Magento/Vault/Plugin/PaymentVaultConfigurationProcess.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,18 @@ public function beforeProcess(\Magento\Checkout\Block\Checkout\LayoutProcessor $
6969
return $method->getProviderCode();
7070
};
7171
$activePaymentMethodCodes = array_map($getCodeFunc, $activePaymentMethodList);
72-
$activeVaultCodes = array_map($getCodeFunc, $activeVaultList);
7372
$activeVaultProviderCodes = array_map($getProviderCodeFunc, $activeVaultList);
7473
$activePaymentMethodCodes = array_merge(
7574
$activePaymentMethodCodes,
76-
$activeVaultCodes,
7775
$activeVaultProviderCodes
7876
);
7977

8078
foreach ($configuration as $paymentGroup => $groupConfig) {
81-
foreach (array_keys($groupConfig['methods']) as $paymentCode) {
82-
if (!in_array($paymentCode, $activePaymentMethodCodes)) {
83-
unset($configuration[$paymentGroup]['methods'][$paymentCode]);
84-
}
79+
$notActivePaymentMethodCodes = array_diff(array_keys($groupConfig['methods']), $activePaymentMethodCodes);
80+
foreach ($notActivePaymentMethodCodes as $notActivePaymentMethodCode) {
81+
unset($configuration[$paymentGroup]['methods'][$notActivePaymentMethodCode]);
8582
}
86-
if ($paymentGroup === 'vault' && !empty($activeVaultCodes)) {
83+
if ($paymentGroup === 'vault' && !empty($activeVaultProviderCodes)) {
8784
continue;
8885
}
8986
if (empty($configuration[$paymentGroup]['methods'])) {

app/code/Magento/Vault/Test/Unit/Plugin/PaymentVaultConfigurationProcessTest.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@ public function beforeProcessDataProvider()
112112
$jsLayout['components']['checkout']['children']['steps']['children']['billing-step']
113113
['children']['payment']['children']['renders']['children'] = [
114114
'vault' => [
115-
'methods' => [
116-
'braintree_paypal_vault' => []
117-
]
115+
'methods' => []
118116
],
119117
'braintree' => [
120118
'methods' => [
@@ -134,9 +132,7 @@ public function beforeProcessDataProvider()
134132
$result2['components']['checkout']['children']['steps']['children']['billing-step']
135133
['children']['payment']['children']['renders']['children'] = [
136134
'vault' => [
137-
'methods' => [
138-
'braintree_paypal_vault' => []
139-
]
135+
'methods' => []
140136
],
141137
'braintree' => [
142138
'methods' => [
@@ -156,7 +152,7 @@ public function beforeProcessDataProvider()
156152

157153
return [
158154
[$jsLayout, [], [], $result1],
159-
[$jsLayout, [$vaultPaymentMethod], [], $result2]
155+
[$jsLayout, [$vaultPaymentMethod], [$vaultPaymentMethod], $result2]
160156
];
161157
}
162158
}

0 commit comments

Comments
 (0)