Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
LayoutProcessor Class Reference
Inheritance diagram for LayoutProcessor:
LayoutProcessorInterface

Public Member Functions

 __construct (\Magento\Checkout\Block\Checkout\AttributeMerger $merger, \Magento\Directory\Model\ResourceModel\Country\Collection $countryCollection, \Magento\Directory\Model\ResourceModel\Region\Collection $regionCollection, \Magento\Directory\Model\TopDestinationCountries $topDestinationCountries=null)
 
 process ($jsLayout)
 

Protected Member Functions

 isCityActive ()
 
 isStateActive ()
 

Protected Attributes

 $merger
 
 $countryCollection
 
 $regionCollection
 
 $defaultShippingAddress = null
 

Detailed Description

Definition at line 8 of file LayoutProcessor.php.

Constructor & Destructor Documentation

◆ __construct()

Parameters
\Magento\Checkout\Block\Checkout\AttributeMerger$merger
\Magento\Directory\Model\ResourceModel\Country\Collection$countryCollection
\Magento\Directory\Model\ResourceModel\Region\Collection$regionCollection
\Magento\Directory\Model\TopDestinationCountries$topDestinationCountries@codeCoverageIgnore

Definition at line 42 of file LayoutProcessor.php.

47  {
48  $this->merger = $merger;
49  $this->countryCollection = $countryCollection;
50  $this->regionCollection = $regionCollection;
51  $this->topDestinationCountries = $topDestinationCountries ?:
53  ->get(\Magento\Directory\Model\TopDestinationCountries::class);
54  }

Member Function Documentation

◆ isCityActive()

isCityActive ( )
protected

Show City in Shipping Estimation

Returns
bool @codeCoverageIgnore

Definition at line 62 of file LayoutProcessor.php.

63  {
64  return false;
65  }

◆ isStateActive()

isStateActive ( )
protected

Show State in Shipping Estimation

Returns
bool @codeCoverageIgnore

Definition at line 73 of file LayoutProcessor.php.

74  {
75  return false;
76  }

◆ process()

process (   $jsLayout)

Process js Layout of block

Parameters
array$jsLayout
Returns
array @SuppressWarnings(PHPMD.NPathComplexity)

Implements LayoutProcessorInterface.

Definition at line 85 of file LayoutProcessor.php.

86  {
87  $elements = [
88  'city' => [
89  'visible' => $this->isCityActive(),
90  'formElement' => 'input',
91  'label' => __('City'),
92  'value' => null
93  ],
94  'country_id' => [
95  'visible' => true,
96  'formElement' => 'select',
97  'label' => __('Country'),
98  'options' => [],
99  'value' => null
100  ],
101  'region_id' => [
102  'visible' => true,
103  'formElement' => 'select',
104  'label' => __('State/Province'),
105  'options' => [],
106  'value' => null
107  ],
108  'postcode' => [
109  'visible' => true,
110  'formElement' => 'input',
111  'label' => __('Zip/Postal Code'),
112  'value' => null
113  ]
114  ];
115 
116  if (!isset($jsLayout['components']['checkoutProvider']['dictionaries'])) {
117  $jsLayout['components']['checkoutProvider']['dictionaries'] = [
118  'country_id' => $this->countryCollection->loadByStore()->setForegroundCountries(
119  $this->topDestinationCountries->getTopDestinations()
120  )->toOptionArray(),
121  'region_id' => $this->regionCollection->addAllowedCountriesFilter()->toOptionArray(),
122  ];
123  }
124  if (isset($jsLayout['components']['block-summary']['children']['block-shipping']['children']
125  ['address-fieldsets']['children'])
126  ) {
127  $fieldSetPointer = &$jsLayout['components']['block-summary']['children']['block-shipping']
128  ['children']['address-fieldsets']['children'];
129  $fieldSetPointer = $this->merger->merge($elements, 'checkoutProvider', 'shippingAddress', $fieldSetPointer);
130  $fieldSetPointer['region_id']['config']['skipValidation'] = true;
131  }
132  return $jsLayout;
133  }
__()
Definition: __.php:13

Field Documentation

◆ $countryCollection

$countryCollection
protected

Definition at line 18 of file LayoutProcessor.php.

◆ $defaultShippingAddress

$defaultShippingAddress = null
protected

Definition at line 28 of file LayoutProcessor.php.

◆ $merger

$merger
protected

Definition at line 13 of file LayoutProcessor.php.

◆ $regionCollection

$regionCollection
protected

Definition at line 23 of file LayoutProcessor.php.


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