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\AutoCompleteAddressBr\Plugin; |
||||
10 | |||||
11 | use Magento\Checkout\Block\Checkout\LayoutProcessor; |
||||
12 | use O2TI\AutoCompleteAddressBr\Helper\Config; |
||||
13 | use O2TI\AutoCompleteAddressBr\Model\ChangesFields; |
||||
14 | |||||
15 | /** |
||||
16 | * CheckoutAutoCompleteAddressBr - Change Components. |
||||
17 | */ |
||||
18 | class CheckoutAutoCompleteAddressBr |
||||
19 | { |
||||
20 | /** |
||||
21 | * @var Config |
||||
22 | */ |
||||
23 | private $config; |
||||
24 | |||||
25 | /** |
||||
26 | * @param Config $config |
||||
27 | * @param ChangesFields $changesFields |
||||
28 | */ |
||||
29 | public function __construct( |
||||
30 | Config $config, |
||||
31 | ChangesFields $changesFields |
||||
32 | ) { |
||||
33 | $this->config = $config; |
||||
34 | $this->changesFields = $changesFields; |
||||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||||
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 | if (isset($jsLayout['components']['checkout']['children']['steps']['children']['identification-step'])) { |
||||
47 | // phpcs:ignore |
||||
48 | $createAccountFields = &$jsLayout['components']['checkout']['children']['steps']['children']['identification-step']['children']['identification']['children']['createAccount']['children']['create-account-fieldset']['children']; |
||||
49 | $createAccountFields = $this->changesFields->changeComponentFields($createAccountFields); |
||||
50 | } |
||||
51 | |||||
52 | return $jsLayout; |
||||
53 | } |
||||
54 | |||||
55 | /** |
||||
56 | * Change Components in Shipping. |
||||
57 | * |
||||
58 | * @param array $jsLayout |
||||
59 | * |
||||
60 | * @return array |
||||
61 | */ |
||||
62 | public function changeShippingFields(array $jsLayout): ?array |
||||
63 | { |
||||
64 | if (isset($jsLayout['components']['checkout']['children']['steps']['children']['shipping-step'])) { |
||||
65 | // phpcs:ignore |
||||
66 | $shippingFields = &$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']['shippingAddress']['children']['shipping-address-fieldset']['children']; |
||||
67 | $shippingFields = $this->changesFields->changeComponentFields($shippingFields); |
||||
68 | } |
||||
69 | |||||
70 | return $jsLayout; |
||||
71 | } |
||||
72 | |||||
73 | /** |
||||
74 | * Change Components in Billing. |
||||
75 | * |
||||
76 | * @param array $jsLayout |
||||
77 | * |
||||
78 | * @return array |
||||
79 | */ |
||||
80 | public function changeBillingFields(array $jsLayout): array |
||||
81 | { |
||||
82 | // phpcs:ignore |
||||
83 | foreach ($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['payments-list']['children'] as &$payment) { |
||||
84 | if (isset($payment['children']['form-fields'])) { |
||||
85 | $billingFields = &$payment['children']['form-fields']['children']; |
||||
86 | $billingFields = $this->changesFields->changeComponentFields($billingFields); |
||||
87 | } |
||||
88 | } |
||||
89 | // phpcs:ignore |
||||
90 | if (isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['afterMethods']['children']['billing-address-form'])) { |
||||
91 | // phpcs:ignore |
||||
92 | $billingAddressOnPage = &$jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['afterMethods']['children']['billing-address-form']['children']['form-fields']['children']; |
||||
93 | $billingAddressOnPage = $this->changesFields->changeComponentFields($billingAddressOnPage); |
||||
94 | } |
||||
95 | // phpcs:ignore |
||||
96 | if (isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['beforeMethods']['children']['billing-address-form'])) { |
||||
97 | // phpcs:ignore |
||||
98 | $billingAddressOnPage = &$jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['beforeMethods']['children']['billing-address-form']['children']['form-fields']['children']; |
||||
99 | $billingAddressOnPage = $this->changesFields->changeComponentFields($billingAddressOnPage); |
||||
100 | } |
||||
101 | |||||
102 | return $jsLayout; |
||||
103 | } |
||||
104 | |||||
105 | /** |
||||
106 | * Select Components for Change. |
||||
107 | * |
||||
108 | * @param LayoutProcessor $layoutProcessor |
||||
109 | * @param callable $proceed |
||||
110 | * @param array $args |
||||
111 | * |
||||
112 | * @return array |
||||
113 | */ |
||||
114 | public function aroundProcess(LayoutProcessor $layoutProcessor, callable $proceed, array $args): array |
||||
0 ignored issues
–
show
The parameter
$layoutProcessor is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||
115 | { |
||||
116 | $jsLayout = $proceed($args); |
||||
117 | if ($this->config->isEnabled()) { |
||||
118 | $jsLayout = $this->changeCreateAccount($jsLayout); |
||||
119 | $jsLayout = $this->changeShippingFields($jsLayout); |
||||
120 | $jsLayout = $this->changeBillingFields($jsLayout); |
||||
121 | } |
||||
122 | |||||
123 | return $jsLayout; |
||||
124 | } |
||||
125 | } |
||||
126 |