1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright © O2TI. All rights reserved. |
4
|
|
|
* |
5
|
|
|
* @author Bruno Elisei <[email protected]> |
6
|
|
|
* See COPYING.txt for license details. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace O2TI\TaxDocumentValidationBr\Plugin; |
10
|
|
|
|
11
|
|
|
use Magento\Checkout\Block\Checkout\LayoutProcessor; |
12
|
|
|
use O2TI\TaxDocumentValidationBr\Helper\Config; |
13
|
|
|
use O2TI\TaxDocumentValidationBr\Model\ValidationBr; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class CheckoutTaxDocumentValidationBrAddRule - Change componentes for validation atribute. |
17
|
|
|
*/ |
18
|
|
|
class CheckoutTaxDocumentValidationBrAddRule |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var Config |
22
|
|
|
*/ |
23
|
|
|
private $config; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param Config $config |
27
|
|
|
* @param ValidationBr $validationBr |
28
|
|
|
*/ |
29
|
|
|
public function __construct( |
30
|
|
|
Config $config, |
31
|
|
|
ValidationBr $validationBr |
32
|
|
|
) { |
33
|
|
|
$this->config = $config; |
34
|
|
|
$this->validationBr = $validationBr; |
|
|
|
|
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Change Components in Create Account. |
39
|
|
|
* |
40
|
|
|
* @param array $jsLayout |
41
|
|
|
* |
42
|
|
|
* @return array |
43
|
|
|
*/ |
44
|
|
|
public function changeCreateAccount(array $jsLayout): ?array |
45
|
|
|
{ |
46
|
|
|
// phpcs:ignore |
47
|
|
|
if (isset($jsLayout['components']['checkout']['children']['steps']['children']['identification-step']['children']['identification']['children']['createAccount']['children']['create-account-fieldset']['children']) |
48
|
|
|
) { |
49
|
|
|
// phpcs:ignore |
50
|
|
|
$createAccountFields = &$jsLayout['components']['checkout']['children']['steps']['children']['identification-step']['children']['identification']['children']['createAccount']['children']['create-account-fieldset']['children']; |
51
|
|
|
$createAccountFields = $this->validationBr->addRuleValidation($createAccountFields); |
52
|
|
|
$createAccountFields = $this->validationBr->addTooltip($createAccountFields); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return $jsLayout; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Change Components in Shipping. |
60
|
|
|
* |
61
|
|
|
* @param array $jsLayout |
62
|
|
|
* |
63
|
|
|
* @return array |
64
|
|
|
*/ |
65
|
|
|
public function changeShippingFields(array $jsLayout): ?array |
66
|
|
|
{ |
67
|
|
|
// phpcs:ignore |
68
|
|
|
if (isset($jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']['shippingAddress']['children']['shipping-address-fieldset']['children']) |
69
|
|
|
) { |
70
|
|
|
// phpcs:ignore |
71
|
|
|
$shippingFields = &$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']['shippingAddress']['children']['shipping-address-fieldset']['children']; |
72
|
|
|
$shippingFields = $this->validationBr->addRuleValidation($shippingFields); |
73
|
|
|
$shippingFields = $this->validationBr->addTooltip($shippingFields); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return $jsLayout; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Change Components in Billing. |
81
|
|
|
* |
82
|
|
|
* @param array $jsLayout |
83
|
|
|
* |
84
|
|
|
* @return array |
85
|
|
|
*/ |
86
|
|
|
public function changeBillingFields(array $jsLayout): array |
87
|
|
|
{ |
88
|
|
|
// phpcs:ignore |
89
|
|
|
foreach ($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['payments-list']['children'] as &$payment) { |
90
|
|
|
if (isset($payment['children']['form-fields'])) { |
91
|
|
|
if (isset($payment['children']['form-fields']['children'])) { |
92
|
|
|
$billingFields = &$payment['children']['form-fields']['children']; |
93
|
|
|
$billingFields = $this->validationBr->addRuleValidation($billingFields); |
94
|
|
|
$billingFields = $this->validationBr->addTooltip($billingFields); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
// phpcs:ignore |
99
|
|
|
if (isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['afterMethods']['children']['billing-address-form']) |
100
|
|
|
) { |
101
|
|
|
// phpcs:ignore |
102
|
|
|
$billingAddressOnPage = &$jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['afterMethods']['children']['billing-address-form']['children']['form-fields']['children']; |
103
|
|
|
$billingAddressOnPage = $this->validationBr->addRuleValidation($billingAddressOnPage); |
104
|
|
|
$billingAddressOnPage = $this->validationBr->addTooltip($billingAddressOnPage); |
105
|
|
|
} |
106
|
|
|
// phpcs:ignore |
107
|
|
|
if (isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['beforeMethods']['children']['billing-address-form']) |
108
|
|
|
) { |
109
|
|
|
// phpcs:ignore |
110
|
|
|
$billingAddressOnPage = &$jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['beforeMethods']['children']['billing-address-form']['children']['form-fields']['children']; |
111
|
|
|
$billingAddressOnPage = $this->validationBr->addRuleValidation($billingAddressOnPage); |
112
|
|
|
$billingAddressOnPage = $this->validationBr->addTooltip($billingAddressOnPage); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
return $jsLayout; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Select Components for Change. |
120
|
|
|
* |
121
|
|
|
* @param LayoutProcessor $layoutProcessor |
122
|
|
|
* @param callable $proceed |
123
|
|
|
* @param array $args |
124
|
|
|
* |
125
|
|
|
* @return array |
126
|
|
|
*/ |
127
|
|
|
public function aroundProcess(LayoutProcessor $layoutProcessor, callable $proceed, array $args): array |
128
|
|
|
{ |
129
|
|
|
$jsLayout = $proceed($args); |
130
|
|
|
if ($this->config->isEnabled()) { |
131
|
|
|
$jsLayout = $this->changeCreateAccount($jsLayout); |
132
|
|
|
$jsLayout = $this->changeShippingFields($jsLayout); |
133
|
|
|
$jsLayout = $this->changeBillingFields($jsLayout); |
134
|
|
|
$layoutProcessor = $layoutProcessor; |
|
|
|
|
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
return $jsLayout; |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|