| 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\AdvancedFieldsCheckout\Plugin; |
||
| 10 | |||
| 11 | use Magento\Checkout\Block\Checkout\LayoutProcessor; |
||
| 12 | use O2TI\AdvancedFieldsCheckout\Helper\Config; |
||
| 13 | use O2TI\AdvancedFieldsCheckout\Model\AddtionalClasses; |
||
| 14 | use O2TI\AdvancedFieldsCheckout\Model\Autocomplete; |
||
| 15 | use O2TI\AdvancedFieldsCheckout\Model\Placeholder; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * CheckoutAdvancedFieldsCheckout - Change Components. |
||
| 19 | */ |
||
| 20 | class CheckoutAdvancedFieldsCheckout |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @var Config |
||
| 24 | */ |
||
| 25 | protected $config; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var AddtionalClasses |
||
| 29 | */ |
||
| 30 | protected $addtionalClasses; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var Autocomplete |
||
| 34 | */ |
||
| 35 | protected $autocomplete; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var Placeholder |
||
| 39 | */ |
||
| 40 | protected $placeholder; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @param Config $config |
||
| 44 | * @param AddtionalClasses $addtionalClasses |
||
| 45 | * @param Autocomplete $autocomplete |
||
| 46 | * @param Placeholder $placeholder |
||
| 47 | */ |
||
| 48 | public function __construct( |
||
| 49 | Config $config, |
||
| 50 | AddtionalClasses $addtionalClasses, |
||
| 51 | Autocomplete $autocomplete, |
||
| 52 | Placeholder $placeholder |
||
| 53 | ) { |
||
| 54 | $this->config = $config; |
||
| 55 | $this->addtionalClasses = $addtionalClasses; |
||
| 56 | $this->autocomplete = $autocomplete; |
||
| 57 | $this->placeholder = $placeholder; |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Change Components in Create Account. |
||
| 62 | * |
||
| 63 | * @param array $jsLayout |
||
| 64 | * |
||
| 65 | * @return array |
||
| 66 | */ |
||
| 67 | public function changeCreateAccount(array $jsLayout): array |
||
| 68 | { |
||
| 69 | // phpcs:ignore |
||
| 70 | if (isset($jsLayout['components']['checkout']['children']['steps']['children']['identification-step']['children']['identification']['children']['createAccount']['children']['create-account-fieldset']['children'])) { |
||
| 71 | // phpcs:ignore |
||
| 72 | $createAccountFields = &$jsLayout['components']['checkout']['children']['steps']['children']['identification-step']['children']['identification']['children']['createAccount']['children']['create-account-fieldset']['children']; |
||
| 73 | if ($this->config->isEnabledClasses()) { |
||
| 74 | $createAccountFields = $this->addtionalClasses->setAddtionalClasses($createAccountFields); |
||
| 75 | } |
||
| 76 | if ($this->config->isEnabledAutocomplete()) { |
||
| 77 | $createAccountFields = $this->autocomplete->setAutocomplete($createAccountFields); |
||
| 78 | } |
||
| 79 | if ($this->config->isEnabledPlaceholder()) { |
||
| 80 | $createAccountFields = $this->placeholder->setPlaceholder($createAccountFields); |
||
| 81 | } |
||
| 82 | } |
||
| 83 | |||
| 84 | return $jsLayout; |
||
| 85 | } |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Change Components in Shipping. |
||
| 89 | * |
||
| 90 | * @param array $jsLayout |
||
| 91 | * |
||
| 92 | * @return array |
||
| 93 | */ |
||
| 94 | public function changeShippingFields(array $jsLayout): array |
||
| 95 | { |
||
| 96 | if (isset($jsLayout['components']['checkout']['children']['steps']['children']['shipping-step'])) { |
||
| 97 | // phpcs:ignore |
||
| 98 | $shippingFields = &$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']['shippingAddress']['children']['shipping-address-fieldset']['children']; |
||
| 99 | if ($this->config->isEnabledClasses()) { |
||
| 100 | $shippingFields = $this->addtionalClasses->setAddtionalClasses($shippingFields); |
||
| 101 | } |
||
| 102 | if ($this->config->isEnabledAutocomplete()) { |
||
| 103 | $shippingFields = $this->autocomplete->setAutocomplete($shippingFields); |
||
| 104 | } |
||
| 105 | if ($this->config->isEnabledPlaceholder()) { |
||
| 106 | $shippingFields = $this->placeholder->setPlaceholder($shippingFields); |
||
| 107 | } |
||
| 108 | } |
||
| 109 | |||
| 110 | return $jsLayout; |
||
| 111 | } |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Change Components in Billing. |
||
| 115 | * |
||
| 116 | * @param array $jsLayout |
||
| 117 | * |
||
| 118 | * @return array |
||
| 119 | */ |
||
| 120 | public function changeBillingFields(array $jsLayout): array |
||
| 121 | { |
||
| 122 | // phpcs:ignore |
||
| 123 | foreach ($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['payments-list']['children'] as &$payment) { |
||
| 124 | if (isset($payment['children']['form-fields'])) { |
||
| 125 | $billingFields = &$payment['children']['form-fields']['children']; |
||
| 126 | if ($this->config->isEnabledClasses()) { |
||
| 127 | $billingFields = $this->addtionalClasses->setAddtionalClasses($billingFields); |
||
| 128 | } |
||
| 129 | if ($this->config->isEnabledAutocomplete()) { |
||
| 130 | $billingFields = $this->autocomplete->setAutocomplete($billingFields); |
||
| 131 | } |
||
| 132 | if ($this->config->isEnabledPlaceholder()) { |
||
| 133 | $billingFields = $this->placeholder->setPlaceholder($billingFields); |
||
| 134 | } |
||
| 135 | } |
||
| 136 | } |
||
| 137 | // phpcs:ignore |
||
| 138 | if (isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['afterMethods']['children']['billing-address-form'])) { |
||
| 139 | // phpcs:ignore |
||
| 140 | $billingAddressOnPage = &$jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['afterMethods']['children']['billing-address-form']['children']['form-fields']['children']; |
||
| 141 | if ($this->config->isEnabledClasses()) { |
||
| 142 | $billingAddressOnPage = $this->addtionalClasses->setAddtionalClasses($billingAddressOnPage); |
||
| 143 | } |
||
| 144 | if ($this->config->isEnabledAutocomplete()) { |
||
| 145 | $billingAddressOnPage = $this->autocomplete->setAutocomplete($billingAddressOnPage); |
||
| 146 | } |
||
| 147 | if ($this->config->isEnabledPlaceholder()) { |
||
| 148 | $billingAddressOnPage = $this->placeholder->setPlaceholder($billingAddressOnPage); |
||
| 149 | } |
||
| 150 | } |
||
| 151 | // phpcs:ignore |
||
| 152 | if (isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['beforeMethods']['children']['billing-address-form'])) { |
||
| 153 | // phpcs:ignore |
||
| 154 | $billingAddressOnPage = &$jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['beforeMethods']['children']['billing-address-form']['children']['form-fields']['children']; |
||
| 155 | if ($this->config->isEnabledClasses()) { |
||
| 156 | $billingAddressOnPage = $this->addtionalClasses->setAddtionalClasses($billingAddressOnPage); |
||
| 157 | } |
||
| 158 | if ($this->config->isEnabledAutocomplete()) { |
||
| 159 | $billingAddressOnPage = $this->autocomplete->setAutocomplete($billingAddressOnPage); |
||
| 160 | } |
||
| 161 | if ($this->config->isEnabledPlaceholder()) { |
||
| 162 | $billingAddressOnPage = $this->placeholder->setPlaceholder($billingAddressOnPage); |
||
| 163 | } |
||
| 164 | } |
||
| 165 | |||
| 166 | return $jsLayout; |
||
| 167 | } |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Select Components for Change. |
||
| 171 | * |
||
| 172 | * @param LayoutProcessor $layoutProcessor |
||
| 173 | * @param callable $proceed |
||
| 174 | * @param array $args |
||
| 175 | * |
||
| 176 | * @return array |
||
| 177 | */ |
||
| 178 | public function aroundProcess(LayoutProcessor $layoutProcessor, callable $proceed, array $args): array |
||
|
0 ignored issues
–
show
|
|||
| 179 | { |
||
| 180 | $jsLayout = $proceed($args); |
||
| 181 | if ($this->config->isEnabled()) { |
||
| 182 | $jsLayout = $this->changeCreateAccount($jsLayout); |
||
| 183 | $jsLayout = $this->changeShippingFields($jsLayout); |
||
| 184 | $jsLayout = $this->changeBillingFields($jsLayout); |
||
| 185 | } |
||
| 186 | |||
| 187 | return $jsLayout; |
||
| 188 | } |
||
| 189 | } |
||
| 190 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.