20 private $attributeMetadataDataProvider;
40 private $checkoutDataHelper;
45 private $storeManager;
50 private $shippingConfig;
62 \
Magento\Customer\Model\AttributeMetadataDataProvider $attributeMetadataDataProvider,
65 \
Magento\Customer\Model\Options $options =
null,
66 Data $checkoutDataHelper =
null,
67 \
Magento\Shipping\Model\Config $shippingConfig =
null,
70 $this->attributeMetadataDataProvider = $attributeMetadataDataProvider;
74 ->get(\
Magento\Customer\Model\Options::class);
78 ->get(\
Magento\Shipping\Model\Config::class);
80 ->get(StoreManagerInterface::class);
88 private function getAddressAttributes()
91 $attributes = $this->attributeMetadataDataProvider->loadAttributesCollection(
93 'customer_register_address' 103 if (isset($elements[
$code][
'label'])) {
118 private function convertElementsToSelect($elements, $attributesToConvert)
120 $codes = array_keys($attributesToConvert);
121 foreach (array_keys($elements) as
$code) {
122 if (!in_array(
$code, $codes)) {
126 if (!is_array($options)) {
129 $elements[
$code][
'dataType'] =
'select';
130 $elements[
$code][
'formElement'] =
'select';
132 foreach ($options as $key =>
$value) {
133 $elements[
$code][
'options'][] = [
151 $attributesToConvert = [
152 'prefix' => [$this->options,
'getNamePrefixOptions'],
153 'suffix' => [$this->options,
'getNameSuffixOptions'],
156 $elements = $this->getAddressAttributes();
157 $elements = $this->convertElementsToSelect($elements, $attributesToConvert);
159 if (isset($jsLayout[
'components'][
'checkout'][
'children'][
'steps'][
'children'][
'billing-step'][
'children']
160 [
'payment'][
'children'])) {
161 $jsLayout[
'components'][
'checkout'][
'children'][
'steps'][
'children'][
'billing-step'][
'children']
162 [
'payment'][
'children'] = $this->processPaymentChildrenComponents(
163 $jsLayout[
'components'][
'checkout'][
'children'][
'steps'][
'children'][
'billing-step'][
'children']
164 [
'payment'][
'children'],
168 if (isset($jsLayout[
'components'][
'checkout'][
'children'][
'steps'][
'children'][
'shipping-step'][
'children']
169 [
'step-config'][
'children'][
'shipping-rates-validation'][
'children'])) {
170 $jsLayout[
'components'][
'checkout'][
'children'][
'steps'][
'children'][
'shipping-step'][
'children']
171 [
'step-config'][
'children'][
'shipping-rates-validation'][
'children'] =
172 $this->processShippingChildrenComponents(
173 $jsLayout[
'components'][
'checkout'][
'children'][
'steps'][
'children'][
'shipping-step'][
'children']
174 [
'step-config'][
'children'][
'shipping-rates-validation'][
'children']
178 if (isset($jsLayout[
'components'][
'checkout'][
'children'][
'steps'][
'children'][
'shipping-step']
179 [
'children'][
'shippingAddress'][
'children'][
'shipping-address-fieldset'][
'children'])) {
180 $fields = $jsLayout[
'components'][
'checkout'][
'children'][
'steps'][
'children'][
'shipping-step']
181 [
'children'][
'shippingAddress'][
'children'][
'shipping-address-fieldset'][
'children'];
182 $jsLayout[
'components'][
'checkout'][
'children'][
'steps'][
'children'][
'shipping-step']
183 [
'children'][
'shippingAddress'][
'children'][
'shipping-address-fieldset'][
'children'] = $this->merger->merge(
199 private function processShippingChildrenComponents($shippingRatesLayout)
201 $activeCarriers = $this->shippingConfig->getActiveCarriers(
202 $this->storeManager->getStore()->getId()
204 foreach (array_keys($shippingRatesLayout) as $carrierName) {
205 $carrierKey = str_replace(
'-rates-validation',
'', $carrierName);
206 if (!array_key_exists($carrierKey, $activeCarriers)) {
207 unset($shippingRatesLayout[$carrierName]);
210 return $shippingRatesLayout;
220 private function processPaymentChildrenComponents(array $paymentLayout, array $elements)
222 if (!isset($paymentLayout[
'payments-list'][
'children'])) {
223 $paymentLayout[
'payments-list'][
'children'] = [];
226 if (!isset($paymentLayout[
'afterMethods'][
'children'])) {
227 $paymentLayout[
'afterMethods'][
'children'] = [];
231 if ($this->checkoutDataHelper->isDisplayBillingOnPaymentMethodAvailable()) {
232 $paymentLayout[
'payments-list'][
'children'] =
233 array_merge_recursive(
234 $paymentLayout[
'payments-list'][
'children'],
235 $this->processPaymentConfiguration(
236 $paymentLayout[
'renders'][
'children'],
241 $component[
'billing-address-form'] = $this->getBillingAddressComponent(
'shared', $elements);
242 $paymentLayout[
'afterMethods'][
'children'] =
243 array_merge_recursive(
245 $paymentLayout[
'afterMethods'][
'children']
249 return $paymentLayout;
259 private function processPaymentConfiguration(array &
$configuration, array $elements)
263 foreach ($groupConfig[
'methods'] as $paymentCode => $paymentComponent) {
264 if (empty($paymentComponent[
'isBillingAddressRequired'])) {
267 $output[$paymentCode .
'-form'] = $this->getBillingAddressComponent($paymentCode, $elements);
282 private function getBillingAddressComponent($paymentCode, $elements)
285 'component' =>
'Magento_Checkout/js/view/billing-address',
286 'displayArea' =>
'billing-address-form-' . $paymentCode,
287 'provider' =>
'checkoutProvider',
288 'deps' =>
'checkoutProvider',
289 'dataScopePrefix' =>
'billingAddress' . $paymentCode,
293 'component' =>
'uiComponent',
294 'displayArea' =>
'additional-fieldsets',
295 'children' => $this->merger->merge(
298 'billingAddress' . $paymentCode,
307 'component' =>
'Magento_Ui/js/form/element/region',
309 'template' =>
'ui/form/field',
310 'elementTmpl' =>
'ui/form/element/select',
311 'customEntry' =>
'billingAddress' . $paymentCode .
'.region',
314 'required-entry' =>
true,
317 'target' =>
'${ $.provider }:${ $.parentScope }.country_id',
318 'field' =>
'country_id',
322 'component' =>
'Magento_Ui/js/form/element/post-code',
324 'required-entry' =>
true,
329 'min_text_length' => 0,
334 'min_text_length' => 0,
340 'description' =>
__(
'For delivery questions.'),
call_user_func($callable, $param)
__construct(\Magento\Customer\Model\AttributeMetadataDataProvider $attributeMetadataDataProvider, \Magento\Ui\Component\Form\AttributeMapper $attributeMapper, AttributeMerger $merger, \Magento\Customer\Model\Options $options=null, Data $checkoutDataHelper=null, \Magento\Shipping\Model\Config $shippingConfig=null, StoreManagerInterface $storeManager=null)