Skip to content

Commit

Permalink
VEOS-9 - Make module work also for street lines 3,4
Browse files Browse the repository at this point in the history
  • Loading branch information
glevhen committed Nov 9, 2023
1 parent b2c4b88 commit d042d66
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions etc/frontend/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<item name="route" xsi:type="string">street.0</item>
<item name="company" xsi:type="string">company</item>
<item name="street_number" xsi:type="string">street.1</item>
<item name="street_number_addition" xsi:type="string">street.2</item>
<item name="locality" xsi:type="string">city</item>
<item name="postal_code" xsi:type="string">postcode</item>
<item name="administrative_area_level_1" xsi:type="string">region</item>
Expand Down
17 changes: 15 additions & 2 deletions view/frontend/templates/checkout/google-autocomplete-js.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
<?php if ((int) $googleAutocompleteSettings->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;
<?php endif; ?>
default:
address[type] = component.long_name;
}
});
});

Expand All @@ -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);
}
});
Expand Down

0 comments on commit d042d66

Please sign in to comment.