From d042d667053447d17e2749e8f2dc8f3e07f00deb Mon Sep 17 00:00:00 2001 From: Yevhen Date: Thu, 9 Nov 2023 12:30:10 +0200 Subject: [PATCH] VEOS-9 - Make module work also for street lines 3,4 --- etc/frontend/di.xml | 1 + .../checkout/google-autocomplete-js.phtml | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/etc/frontend/di.xml b/etc/frontend/di.xml index 696a471..84f9816 100644 --- a/etc/frontend/di.xml +++ b/etc/frontend/di.xml @@ -9,6 +9,7 @@ street.0 company street.1 + street.2 city postcode region diff --git a/view/frontend/templates/checkout/google-autocomplete-js.phtml b/view/frontend/templates/checkout/google-autocomplete-js.phtml index c752ee9..8387e37 100644 --- a/view/frontend/templates/checkout/google-autocomplete-js.phtml +++ b/view/frontend/templates/checkout/google-autocomplete-js.phtml @@ -61,7 +61,20 @@ if (!$apiKey) { event.detail.addressComponents.forEach(component => { component.types.forEach(type => { // Use type as the key and long_name as the value - address[type] = type === 'country' ? component.short_name : component.long_name; + switch (type) { + case 'country': + address[type] = component.short_name; + break; + getStreetLinesQty() > 2): ?> + case 'street_number': + address[type] = component.long_name.match(/\d+/)[0]; + address['street_number_addition'] = component.long_name.match(/[a-zA-Z]+/g) ? + component.long_name.match(/[a-zA-Z]+/g)[0] : ''; + break; + + default: + address[type] = component.long_name; + } }); }); @@ -88,7 +101,7 @@ if (!$apiKey) { const value = address[key]; const identifier = `address.${fieldMappings[key]}`; - if (value !== undefined && value.length > 0) { + if (value !== undefined && (value.length > 0 || key === 'street_number_addition')) { component.set(identifier, value); } });