Skip to content

Commit

Permalink
MAGETWO-60351: Unnecessary disabled payment methods on checkout page #…
Browse files Browse the repository at this point in the history
  • Loading branch information
omiroshnichenko committed Nov 4, 2016
1 parent 79f392c commit 0644f24
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,9 @@ public function beforeProcess(\Magento\Checkout\Block\Checkout\LayoutProcessor $
$activePaymentMethodCodes = array_map($getCodeFunc, $activePaymentMethodList);

foreach ($configuration as $paymentGroup => $groupConfig) {
foreach (array_keys($groupConfig['methods']) as $paymentCode) {
if (!in_array($paymentCode, $activePaymentMethodCodes)) {
unset($configuration[$paymentGroup]['methods'][$paymentCode]);
}
$notActivePaymentMethodCodes = array_diff(array_keys($groupConfig['methods']), $activePaymentMethodCodes);
foreach ($notActivePaymentMethodCodes as $notActivePaymentMethodCode) {
unset($configuration[$paymentGroup]['methods'][$notActivePaymentMethodCode]);
}
if (empty($configuration[$paymentGroup]['methods'])) {
unset($configuration[$paymentGroup]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,23 @@ public function testBeforeProcess($jsLayout, $activePaymentList, $expectedResult
public function beforeProcessDataProvider()
{
$jsLayout['components']['checkout']['children']['steps']['children']['billing-step']
['children']['payment']['children']['renders']['children'] = [
'braintree' => [
'methods' => [
'braintree_paypal' => [],
'braintree' => []
]
],
'paypal-payments' => [
'methods' => [
'payflowpro' => [],
'payflow_link' => []
]
]
];
$result1['components']['checkout']['children']['steps']['children']['billing-step']
['children']['payment']['children']['renders']['children'] = [];
$result2['components']['checkout']['children']['steps']['children']['billing-step']
['children']['payment']['children']['renders']['children'] = [
'braintree' => [
'methods' => [
Expand All @@ -106,8 +123,6 @@ public function beforeProcessDataProvider()
]
]
];
$result['components']['checkout']['children']['steps']['children']['billing-step']
['children']['payment']['children']['renders']['children'] = [];

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

return [
[$jsLayout, [], $result],
[$jsLayout, [$braintreePaymentMethod, $braintreePaypalPaymentMethod], $jsLayout]
[$jsLayout, [], $result1],
[$jsLayout, [$braintreePaymentMethod, $braintreePaypalPaymentMethod], $result2]
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,18 @@ public function beforeProcess(\Magento\Checkout\Block\Checkout\LayoutProcessor $
return $method->getProviderCode();
};
$activePaymentMethodCodes = array_map($getCodeFunc, $activePaymentMethodList);
$activeVaultCodes = array_map($getCodeFunc, $activeVaultList);
$activeVaultProviderCodes = array_map($getProviderCodeFunc, $activeVaultList);
$activePaymentMethodCodes = array_merge(
$activePaymentMethodCodes,
$activeVaultCodes,
$activeVaultProviderCodes
);

foreach ($configuration as $paymentGroup => $groupConfig) {
foreach (array_keys($groupConfig['methods']) as $paymentCode) {
if (!in_array($paymentCode, $activePaymentMethodCodes)) {
unset($configuration[$paymentGroup]['methods'][$paymentCode]);
}
$notActivePaymentMethodCodes = array_diff(array_keys($groupConfig['methods']), $activePaymentMethodCodes);
foreach ($notActivePaymentMethodCodes as $notActivePaymentMethodCode) {
unset($configuration[$paymentGroup]['methods'][$notActivePaymentMethodCode]);
}
if ($paymentGroup === 'vault' && !empty($activeVaultCodes)) {
if ($paymentGroup === 'vault' && !empty($activeVaultProviderCodes)) {
continue;
}
if (empty($configuration[$paymentGroup]['methods'])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ public function beforeProcessDataProvider()
$jsLayout['components']['checkout']['children']['steps']['children']['billing-step']
['children']['payment']['children']['renders']['children'] = [
'vault' => [
'methods' => [
'braintree_paypal_vault' => []
]
'methods' => []
],
'braintree' => [
'methods' => [
Expand All @@ -134,9 +132,7 @@ public function beforeProcessDataProvider()
$result2['components']['checkout']['children']['steps']['children']['billing-step']
['children']['payment']['children']['renders']['children'] = [
'vault' => [
'methods' => [
'braintree_paypal_vault' => []
]
'methods' => []
],
'braintree' => [
'methods' => [
Expand All @@ -156,7 +152,7 @@ public function beforeProcessDataProvider()

return [
[$jsLayout, [], [], $result1],
[$jsLayout, [$vaultPaymentMethod], [], $result2]
[$jsLayout, [$vaultPaymentMethod], [$vaultPaymentMethod], $result2]
];
}
}

0 comments on commit 0644f24

Please sign in to comment.