11<?php
2+ /**
3+ * Copyright © Experius B.V. All rights reserved.
4+ * See COPYING.txt for license details.
5+ */
6+ declare (strict_types=1 );
27
38namespace Experius \ExtraCheckoutAddressFields \Block \Checkout ;
49
5- class LayoutProcessor implements \Magento \Checkout \Block \Checkout \LayoutProcessorInterface
10+ use Magento \Checkout \Block \Checkout \LayoutProcessorInterface ;
11+
12+ class LayoutProcessor implements LayoutProcessorInterface
613{
714 protected $ helper ;
815
16+ /**
17+ * LayoutProcessor constructor.
18+ *
19+ * @param \Experius\ExtraCheckoutAddressFields\Helper\Data $helper
20+ */
921 public function __construct (
1022 \Experius \ExtraCheckoutAddressFields \Helper \Data $ helper
11- )
12- {
23+ ) {
1324 $ this ->helper = $ helper ;
1425 }
1526
16- public function process ($ result ) {
27+ /**
28+ * @param array $result
29+ * @return array
30+ */
31+ public function process ($ result )
32+ {
1733 $ result = $ this ->getShippingFormFields ($ result );
1834 $ result = $ this ->getBillingFormFields ($ result );
1935 return $ result ;
2036 }
2137
22- public function getAdditionalFields ($ addressType ='shipping ' ){
23- if ($ addressType =='shipping ' ) {
38+ /**
39+ * @param string $addressType
40+ * @return array
41+ */
42+ public function getAdditionalFields ($ addressType ='shipping ' )
43+ {
44+ if ($ addressType =='shipping ' ) {
2445 return $ this ->helper ->getExtraCheckoutAddressFields ('extra_checkout_shipping_address_fields ' );
2546 }
2647 return $ this ->helper ->getExtraCheckoutAddressFields ('extra_checkout_billing_address_fields ' );
2748 }
2849
29- public function getShippingFormFields ($ result ){
30- if (isset ($ result ['components ' ]['checkout ' ]['children ' ]['steps ' ]['children ' ]
50+ /**
51+ * @param $result
52+ * @return mixed
53+ */
54+ public function getShippingFormFields ($ result )
55+ {
56+ if (isset ($ result ['components ' ]['checkout ' ]['children ' ]['steps ' ]['children ' ]
3157 ['shipping-step ' ]['children ' ]['shippingAddress ' ]['children ' ]
3258 ['shipping-address-fieldset ' ])
33- ){
34-
35- $ shippingPostcodeFields = $ this ->getFields ('shippingAddress.custom_attributes ' ,'shipping ' );
59+ ) {
60+ $ shippingPostcodeFields = $ this ->getFields ('shippingAddress.custom_attributes ' , 'shipping ' );
3661
3762 $ shippingFields = $ result ['components ' ]['checkout ' ]['children ' ]['steps ' ]['children ' ]
3863 ['shipping-step ' ]['children ' ]['shippingAddress ' ]['children ' ]
3964 ['shipping-address-fieldset ' ]['children ' ];
4065
41- if (isset ($ shippingFields ['street ' ])){
66+ if (isset ($ shippingFields ['street ' ])) {
4267 unset($ shippingFields ['street ' ]['children ' ][1 ]['validation ' ]);
4368 unset($ shippingFields ['street ' ]['children ' ][2 ]['validation ' ]);
4469 }
4570
46- $ shippingFields = array_replace_recursive ($ shippingFields ,$ shippingPostcodeFields );
71+ $ shippingFields = array_replace_recursive ($ shippingFields , $ shippingPostcodeFields );
4772
4873 $ result ['components ' ]['checkout ' ]['children ' ]['steps ' ]['children ' ]
4974 ['shipping-step ' ]['children ' ]['shippingAddress ' ]['children ' ]
5075 ['shipping-address-fieldset ' ]['children ' ] = $ shippingFields ;
51-
5276 }
5377
5478 return $ result ;
5579 }
5680
57- public function getBillingFormFields ($ result ){
58- if (isset ($ result ['components ' ]['checkout ' ]['children ' ]['steps ' ]['children ' ]
81+ /**
82+ * @param $result
83+ * @return mixed
84+ */
85+ public function getBillingFormFields ($ result )
86+ {
87+ if (isset ($ result ['components ' ]['checkout ' ]['children ' ]['steps ' ]['children ' ]
5988 ['billing-step ' ]['children ' ]['payment ' ]['children ' ]
6089 ['payments-list ' ])) {
61-
6290 $ paymentForms = $ result ['components ' ]['checkout ' ]['children ' ]['steps ' ]['children ' ]
6391 ['billing-step ' ]['children ' ]['payment ' ]['children ' ]
6492 ['payments-list ' ]['children ' ];
6593
6694 foreach ($ paymentForms as $ paymentMethodForm => $ paymentMethodValue ) {
67-
6895 $ paymentMethodCode = str_replace ('-form ' , '' , $ paymentMethodForm );
6996
7097 if (!isset ($ result ['components ' ]['checkout ' ]['children ' ]['steps ' ]['children ' ]['billing-step ' ]['children ' ]['payment ' ]['children ' ]['payments-list ' ]['children ' ][$ paymentMethodCode . '-form ' ])) {
@@ -75,7 +102,7 @@ public function getBillingFormFields($result){
75102 ['billing-step ' ]['children ' ]['payment ' ]['children ' ]
76103 ['payments-list ' ]['children ' ][$ paymentMethodCode . '-form ' ]['children ' ]['form-fields ' ]['children ' ];
77104
78- $ billingPostcodeFields = $ this ->getFields ('billingAddress ' . $ paymentMethodCode . '.custom_attributes ' ,'billing ' );
105+ $ billingPostcodeFields = $ this ->getFields ('billingAddress ' . $ paymentMethodCode . '.custom_attributes ' , 'billing ' );
79106
80107 $ billingFields = array_replace_recursive ($ billingFields , $ billingPostcodeFields );
81108
@@ -88,23 +115,34 @@ public function getBillingFormFields($result){
88115 return $ result ;
89116 }
90117
91- public function getFields ($ scope ,$ addressType ){
118+ /**
119+ * @param $scope
120+ * @param $addressType
121+ * @return array
122+ */
123+ public function getFields ($ scope , $ addressType )
124+ {
92125 $ fields = [];
93- foreach ($ this ->getAdditionalFields ($ addressType ) as $ field ){
94- $ fields [$ field ] = $ this ->getField ($ field ,$ scope );
126+ foreach ($ this ->getAdditionalFields ($ addressType ) as $ field ) {
127+ $ fields [$ field ] = $ this ->getField ($ field , $ scope );
95128 }
96129 return $ fields ;
97130 }
98131
99- public function getField ($ attributeCode ,$ scope ) {
132+ /**
133+ * @param $attributeCode
134+ * @param $scope
135+ * @return array
136+ */
137+ public function getField ($ attributeCode , $ scope )
138+ {
100139 $ field = [
101140 'config ' => [
102141 'customScope ' => $ scope ,
103142 ],
104- 'dataScope ' => $ scope . '. ' . $ attributeCode ,
143+ 'dataScope ' => $ scope . '. ' . $ attributeCode ,
105144 ];
106145
107146 return $ field ;
108147 }
109-
110- }
148+ }
0 commit comments