|
7 | 7 |
|
8 | 8 | namespace Experius\ExtraCheckoutAddressFields\Block\Checkout; |
9 | 9 |
|
| 10 | +use Experius\ExtraCheckoutAddressFields\Helper\Data; |
10 | 11 | use Magento\Checkout\Block\Checkout\LayoutProcessorInterface; |
11 | 12 |
|
12 | 13 | class LayoutProcessor implements LayoutProcessorInterface |
13 | 14 | { |
| 15 | + /** |
| 16 | + * Form element mapping |
| 17 | + * |
| 18 | + * @var array |
| 19 | + */ |
| 20 | + private $formElementMap = [ |
| 21 | + 'text' => 'input', |
| 22 | + 'hidden' => 'input', |
| 23 | + 'boolean' => 'checkbox', |
| 24 | + ]; |
| 25 | + /** |
| 26 | + * @var Data |
| 27 | + */ |
14 | 28 | protected $helper; |
| 29 | + /** |
| 30 | + * @var \Magento\Eav\Api\AttributeRepositoryInterface |
| 31 | + */ |
| 32 | + private $attributeRepository; |
15 | 33 |
|
16 | 34 | /** |
17 | 35 | * LayoutProcessor constructor. |
18 | 36 | * |
19 | | - * @param \Experius\ExtraCheckoutAddressFields\Helper\Data $helper |
| 37 | + * @param Data $helper |
| 38 | + * @param \Magento\Eav\Api\AttributeRepositoryInterface $attributeRepository |
20 | 39 | */ |
21 | 40 | public function __construct( |
22 | | - \Experius\ExtraCheckoutAddressFields\Helper\Data $helper |
| 41 | + Data $helper, |
| 42 | + \Magento\Eav\Api\AttributeRepositoryInterface $attributeRepository |
23 | 43 | ) { |
24 | 44 | $this->helper = $helper; |
| 45 | + $this->attributeRepository = $attributeRepository; |
25 | 46 | } |
26 | 47 |
|
27 | 48 | /** |
@@ -136,13 +157,27 @@ public function getFields($scope, $addressType) |
136 | 157 | */ |
137 | 158 | public function getField($attributeCode, $scope) |
138 | 159 | { |
139 | | - $field = [ |
| 160 | + $attribute = $this->attributeRepository->get('customer_address', $attributeCode); |
| 161 | + |
| 162 | + $inputType = $attribute->getFrontendInput(); |
| 163 | + if (isset($this->formElementMap[$inputType])) { |
| 164 | + $inputType = $this->formElementMap[$inputType]; |
| 165 | + } |
| 166 | + |
| 167 | + return [ |
| 168 | + 'component' => 'Magento_Ui/js/form/element/abstract', |
140 | 169 | 'config' => [ |
141 | 170 | 'customScope' => $scope, |
| 171 | + 'template' => 'ui/form/field', |
| 172 | + 'elementTmpl' => 'ui/form/element/' . $inputType |
142 | 173 | ], |
143 | 174 | 'dataScope' => $scope . '.' . $attributeCode, |
| 175 | + 'sortOrder' => $attribute->getSortOrder(), |
| 176 | + 'visible' => true, |
| 177 | + 'provider' => 'checkoutProvider', |
| 178 | + 'validation' => $attribute->getValidationRules(), |
| 179 | + 'options' => $attribute->getOptions(), |
| 180 | + 'label' => __($attribute->getStoreLabel()) |
144 | 181 | ]; |
145 | | - |
146 | | - return $field; |
147 | 182 | } |
148 | 183 | } |
0 commit comments