Skip to content

Commit 04396e6

Browse files
committed
[FEATURE] Use attribute configuration for field display
1 parent 1fc6ca9 commit 04396e6

2 files changed

Lines changed: 78 additions & 5 deletions

File tree

Block/Checkout/LayoutProcessor.php

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,42 @@
77

88
namespace Experius\ExtraCheckoutAddressFields\Block\Checkout;
99

10+
use Experius\ExtraCheckoutAddressFields\Helper\Data;
1011
use Magento\Checkout\Block\Checkout\LayoutProcessorInterface;
1112

1213
class LayoutProcessor implements LayoutProcessorInterface
1314
{
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+
*/
1428
protected $helper;
29+
/**
30+
* @var \Magento\Eav\Api\AttributeRepositoryInterface
31+
*/
32+
private $attributeRepository;
1533

1634
/**
1735
* LayoutProcessor constructor.
1836
*
19-
* @param \Experius\ExtraCheckoutAddressFields\Helper\Data $helper
37+
* @param Data $helper
38+
* @param \Magento\Eav\Api\AttributeRepositoryInterface $attributeRepository
2039
*/
2140
public function __construct(
22-
\Experius\ExtraCheckoutAddressFields\Helper\Data $helper
41+
Data $helper,
42+
\Magento\Eav\Api\AttributeRepositoryInterface $attributeRepository
2343
) {
2444
$this->helper = $helper;
45+
$this->attributeRepository = $attributeRepository;
2546
}
2647

2748
/**
@@ -136,13 +157,27 @@ public function getFields($scope, $addressType)
136157
*/
137158
public function getField($attributeCode, $scope)
138159
{
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',
140169
'config' => [
141170
'customScope' => $scope,
171+
'template' => 'ui/form/field',
172+
'elementTmpl' => 'ui/form/element/' . $inputType
142173
],
143174
'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())
144181
];
145-
146-
return $field;
147182
}
148183
}

CHANGELOG.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
## 1.2.0 (2020-08-24)
2+
3+
[View Release](git@github.com:experius/Magento-2-Module-Experius-ExtraCheckoutAddressFields.git/commits/tag/1.2.0)
4+
5+
* [FEATURE] Use attribute configuration for field display *(Lewis Voncken)*
6+
7+
8+
## 1.1.0 (2020-08-24)
9+
10+
[View Release](git@github.com:experius/Magento-2-Module-Experius-ExtraCheckoutAddressFields.git/commits/tag/1.1.0)
11+
12+
* [BUGFIX] Take in account cases where fields are not returned or are null in the helper *(Sylvain Rayé)*
13+
* [REFACTOR] Clean up code and added license *(Lewis Voncken)*
14+
15+
16+
## 1.0.2 (2018-03-13)
17+
18+
[View Release](git@github.com:experius/Magento-2-Module-Experius-ExtraCheckoutAddressFields.git/commits/tag/1.0.2)
19+
20+
* [BUGFIX] Fixed issue with orders with virtual products only and no shipping address *(Derrick Heesbeen)*
21+
22+
23+
## 1.0.1 (2018-01-03)
24+
25+
[View Release](git@github.com:experius/Magento-2-Module-Experius-ExtraCheckoutAddressFields.git/commits/tag/1.0.1)
26+
27+
* Update composer.json *(Robbert)*
28+
* Update README.md *(Robbert)*
29+
* [BUGFIX] Billingaddress extra address field save and transport to order, removed duplicate code *(Derrick Heesbeen)*
30+
31+
32+
## 1.0.0 (2017-03-28)
33+
34+
[View Release](git@github.com:experius/Magento-2-Module-Experius-ExtraCheckoutAddressFields.git/commits/tag/1.0.0)
35+
36+
* First Version *(Derrick Heesbeen)*
37+
38+

0 commit comments

Comments
 (0)