Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
PaymentConfigurationProcess Class Reference

Public Member Functions

 __construct (\Magento\Payment\Api\PaymentMethodListInterface $paymentMethodList, \Magento\Store\Model\StoreManagerInterface $storeManager)
 
 beforeProcess (\Magento\Checkout\Block\Checkout\LayoutProcessor $processor, $jsLayout)
 

Detailed Description

Class PaymentConfigurationProcess

Removes inactive payment methods and group from checkout configuration.

Definition at line 13 of file PaymentConfigurationProcess.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Payment\Api\PaymentMethodListInterface  $paymentMethodList,
\Magento\Store\Model\StoreManagerInterface  $storeManager 
)
Parameters
\Magento\Payment\Api\PaymentMethodListInterface$paymentMethodList
\Magento\Store\Model\StoreManagerInterface$storeManager

Definition at line 29 of file PaymentConfigurationProcess.php.

32  {
33  $this->paymentMethodList = $paymentMethodList;
34  $this->storeManager = $storeManager;
35  }
$storeManager

Member Function Documentation

◆ beforeProcess()

beforeProcess ( \Magento\Checkout\Block\Checkout\LayoutProcessor  $processor,
  $jsLayout 
)

Checkout LayoutProcessor before process plugin.

Parameters
\Magento\Checkout\Block\Checkout\LayoutProcessor$processor
array$jsLayout
Returns
array @SuppressWarnings(PHPMD.UnusedFormalParameter)

Definition at line 45 of file PaymentConfigurationProcess.php.

46  {
47  $configuration = &$jsLayout['components']['checkout']['children']['steps']['children']['billing-step']
48  ['children']['payment']['children']['renders']['children'];
49 
50  if (!isset($configuration)) {
51  return [$jsLayout];
52  }
53 
54  $storeId = $this->storeManager->getStore()->getId();
55  $activePaymentMethodList = $this->paymentMethodList->getActiveList($storeId);
56  $getCodeFunc = function ($method) {
57  return $method->getCode();
58  };
59  $activePaymentMethodCodes = array_map($getCodeFunc, $activePaymentMethodList);
60 
61  foreach ($configuration as $paymentGroup => $groupConfig) {
62  $notActivePaymentMethodCodes = array_diff(array_keys($groupConfig['methods']), $activePaymentMethodCodes);
63  foreach ($notActivePaymentMethodCodes as $notActivePaymentMethodCode) {
64  unset($configuration[$paymentGroup]['methods'][$notActivePaymentMethodCode]);
65  }
66  if (empty($configuration[$paymentGroup]['methods'])) {
67  unset($configuration[$paymentGroup]);
68  }
69  }
70 
71  return [$jsLayout];
72  }
$configuration
Definition: index.php:33
$method
Definition: info.phtml:13

The documentation for this class was generated from the following file: