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\BrazilianDocument; |
||
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 | * @var BrazilianDocument |
||
27 | */ |
||
28 | private $brazilianDocument; |
||
29 | |||
30 | /** |
||
31 | * @param Config $config |
||
32 | * @param BrazilianDocument $brazilianDocument |
||
33 | */ |
||
34 | public function __construct( |
||
35 | Config $config, |
||
36 | BrazilianDocument $brazilianDocument |
||
37 | ) { |
||
38 | $this->config = $config; |
||
39 | $this->brazilianDocument = $brazilianDocument; |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * Change Components in Create Account. |
||
44 | * |
||
45 | * @param array $jsLayout |
||
46 | * |
||
47 | * @return array |
||
48 | */ |
||
49 | public function changeCreateAccount(array $jsLayout): ?array |
||
50 | { |
||
51 | // phpcs:ignore |
||
52 | if (isset($jsLayout['components']['checkout']['children']['steps']['children']['identification-step']['children']['identification']['children']['createAccount']['children']['create-account-fieldset']['children']) |
||
53 | ) { |
||
54 | // phpcs:ignore |
||
55 | $createAccountFields = &$jsLayout['components']['checkout']['children']['steps']['children']['identification-step']['children']['identification']['children']['createAccount']['children']['create-account-fieldset']['children']; |
||
56 | $createAccountFields = $this->brazilianDocument->addRuleValidation($createAccountFields); |
||
57 | $createAccountFields = $this->brazilianDocument->addTooltip($createAccountFields); |
||
58 | } |
||
59 | |||
60 | return $jsLayout; |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * Change Components in Shipping. |
||
65 | * |
||
66 | * @param array $jsLayout |
||
67 | * |
||
68 | * @return array |
||
69 | */ |
||
70 | public function changeShippingFields(array $jsLayout): ?array |
||
71 | { |
||
72 | // phpcs:ignore |
||
73 | if (isset($jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']['shippingAddress']['children']['shipping-address-fieldset']['children']) |
||
74 | ) { |
||
75 | // phpcs:ignore |
||
76 | $shippingFields = &$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']['shippingAddress']['children']['shipping-address-fieldset']['children']; |
||
77 | $shippingFields = $this->brazilianDocument->addRuleValidation($shippingFields); |
||
78 | $shippingFields = $this->brazilianDocument->addTooltip($shippingFields); |
||
79 | } |
||
80 | |||
81 | return $jsLayout; |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * Change Components in Billing. |
||
86 | * |
||
87 | * @param array $jsLayout |
||
88 | * |
||
89 | * @return array |
||
90 | */ |
||
91 | public function changeBillingFields(array $jsLayout): array |
||
92 | { |
||
93 | // phpcs:ignore |
||
94 | foreach ($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['payments-list']['children'] as &$payment) { |
||
95 | if (isset($payment['children']['form-fields'])) { |
||
96 | if (isset($payment['children']['form-fields']['children'])) { |
||
97 | $billingFields = &$payment['children']['form-fields']['children']; |
||
98 | $billingFields = $this->brazilianDocument->addRuleValidation($billingFields); |
||
99 | $billingFields = $this->brazilianDocument->addTooltip($billingFields); |
||
100 | } |
||
101 | } |
||
102 | } |
||
103 | // phpcs:ignore |
||
104 | if (isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['afterMethods']['children']['billing-address-form']) |
||
105 | ) { |
||
106 | // phpcs:ignore |
||
107 | $billingAddressOnPage = &$jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['afterMethods']['children']['billing-address-form']['children']['form-fields']['children']; |
||
108 | $billingAddressOnPage = $this->brazilianDocument->addRuleValidation($billingAddressOnPage); |
||
109 | $billingAddressOnPage = $this->brazilianDocument->addTooltip($billingAddressOnPage); |
||
110 | } |
||
111 | // phpcs:ignore |
||
112 | if (isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['beforeMethods']['children']['billing-address-form']) |
||
113 | ) { |
||
114 | // phpcs:ignore |
||
115 | $billingAddressOnPage = &$jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['beforeMethods']['children']['billing-address-form']['children']['form-fields']['children']; |
||
116 | $billingAddressOnPage = $this->brazilianDocument->addRuleValidation($billingAddressOnPage); |
||
117 | $billingAddressOnPage = $this->brazilianDocument->addTooltip($billingAddressOnPage); |
||
118 | } |
||
119 | |||
120 | return $jsLayout; |
||
121 | } |
||
122 | |||
123 | /** |
||
124 | * Select Components for Change. |
||
125 | * |
||
126 | * @param LayoutProcessor $layoutProcessor |
||
127 | * @param callable $proceed |
||
128 | * @param array $args |
||
129 | * |
||
130 | * @return array |
||
131 | */ |
||
132 | public function aroundProcess(LayoutProcessor $layoutProcessor, callable $proceed, array $args): array |
||
0 ignored issues
–
show
|
|||
133 | { |
||
134 | $jsLayout = $proceed($args); |
||
135 | if ($this->config->isEnabled()) { |
||
136 | $jsLayout = $this->changeCreateAccount($jsLayout); |
||
137 | $jsLayout = $this->changeShippingFields($jsLayout); |
||
138 | $jsLayout = $this->changeBillingFields($jsLayout); |
||
139 | } |
||
140 | |||
141 | return $jsLayout; |
||
142 | } |
||
143 | } |
||
144 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.