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