Skip to content

Instantly share code, notes, and snippets.

@csavoronin
Created March 10, 2023 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csavoronin/4eef032b054cb6a96fa8fb6628a7e5b6 to your computer and use it in GitHub Desktop.
Save csavoronin/4eef032b054cb6a96fa8fb6628a7e5b6 to your computer and use it in GitHub Desktop.
[!] Checkout: Profile fields: The billing address was filled with the data from the shipping address. Fixed.
diff --git a/design/themes/responsive/templates/views/checkout/components/profile_fields.tpl b/design/themes/responsive/templates/views/checkout/components/profile_fields.tpl
index 281fd6016ef..17db17fe430 100644
--- a/design/themes/responsive/templates/views/checkout/components/profile_fields.tpl
+++ b/design/themes/responsive/templates/views/checkout/components/profile_fields.tpl
@@ -100,12 +100,10 @@
{$field_name = "user_data[`$field.field_name`]"}
{$field_value = $user_data[$field.field_name]}
{$field_name_helper = "user_data.`$field.field_name`"}
- {$element_name_helper = $field.field_name|regex_replace:"/^s_|^b_/":""}
{else}
{$field_name = "user_data[fields][`$field.field_id`]"}
{$field_value = $user_data["fields"][$field.field_id]}
{$field_name_helper = "user_data.fields.`$field.field_id`"}
- {$element_name_helper = "fields.`$field.field_name`"}
{/if}
{if $field.field_name == "`$prefix`fullname"}
diff --git a/design/themes/responsive/templates/views/checkout/components/profile_fields/field.tpl b/design/themes/responsive/templates/views/checkout/components/profile_fields/field.tpl
index 3dc758da8b9..21af3a6ae2a 100644
--- a/design/themes/responsive/templates/views/checkout/components/profile_fields/field.tpl
+++ b/design/themes/responsive/templates/views/checkout/components/profile_fields/field.tpl
@@ -8,9 +8,7 @@
id="{$field_id}"
class="cm-state litecheckout__input litecheckout__input--selectable litecheckout__input--selectable--select {if $section == "S"}cm-location-shipping{else}cm-location-billing{/if}{if $field.class} {$field.class}{/if}{$input_meta}"
data-ca-lite-checkout-field="{$field_name_helper}"
- data-ca-lite-checkout-element="{$element_name_helper}"
data-ca-lite-checkout-auto-save-on-change="true"
- data-ca-lite-checkout-last-value="{$field_value}"
aria-label="{$field.description}"
title="{$field.description}"
{$field.attributes|render_tag_attrs nofilter}
@@ -37,9 +35,7 @@
disabled="disabled"
class="cm-state {if $section == "S"}cm-location-shipping{else}cm-location-billing{/if} ty-input-text litecheckout__input hidden{$input_meta}"
data-ca-lite-checkout-field="{$field_name_helper}"
- data-ca-lite-checkout-element="{$element_name_helper}"
data-ca-lite-checkout-auto-save-on-change="true"
- data-ca-lite-checkout-last-value="{$field_value}"
/>
{elseif $field.field_type == "ProfileFieldTypes::COUNTRY"|enum}
@@ -50,9 +46,7 @@
id="{$field_id}"
class="ty-profile-field__select-country cm-country litecheckout__input litecheckout__input--selectable litecheckout__input--selectable--select {if $section == "S"}cm-location-shipping{else}cm-location-billing{/if} {if $field.class} {$field.class}{/if}{$input_meta}"
data-ca-lite-checkout-field="{$field_name_helper}"
- data-ca-lite-checkout-element="{$element_name_helper}"
data-ca-lite-checkout-auto-save-on-change="true"
- data-ca-lite-checkout-last-value="{$field_value}"
aria-label="{$field.description}"
title="{$field.description}"
{$field.attributes|render_tag_attrs nofilter}
@@ -74,9 +68,7 @@
name="{$field_name}"
placeholder=" "
data-ca-lite-checkout-field="{$field_name_helper}"
- data-ca-lite-checkout-element="{$element_name_helper}"
data-ca-lite-checkout-auto-save="true"
- data-ca-lite-checkout-last-value="{$field_value}"
aria-label="{$field.description}"
title="{$field.description}"
{$field.attributes|render_tag_attrs nofilter}
@@ -89,9 +81,7 @@
name="{$field_name}"
value="{"YesNo::YES"|enum}"
data-ca-lite-checkout-field="{$field_name_helper}"
- data-ca-lite-checkout-element="{$element_name_helper}"
data-ca-lite-checkout-auto-save="true"
- data-ca-lite-checkout-last-value="{$field_value}"
autocomplete="{$field.autocomplete}"
aria-label="{$field.description}"
title="{$field.description}"
@@ -118,9 +108,7 @@
name="{$field_name}"
value="{$value}"
data-ca-lite-checkout-field="{$field_name_helper}"
- data-ca-lite-checkout-element="{$element_name_helper}"
data-ca-lite-checkout-auto-save-on-change="true"
- data-ca-lite-checkout-last-value="{$field_value}"
{if (!$field_value && $name@first) || $field_value == $value}checked{/if}
{$field.attributes|render_tag_attrs nofilter}
/>
@@ -132,9 +120,7 @@
autocomplete="{$field.autocomplete}"
id="{$field_id}"
data-ca-lite-checkout-field="{$field_name_helper}"
- data-ca-lite-checkout-element="{$element_name_helper}"
data-ca-lite-checkout-auto-save-on-change="true"
- data-ca-lite-checkout-last-value="{$field_value}"
aria-label="{$field.description}"
title="{$field.description}"
name="{$field_name}"
@@ -155,9 +141,7 @@
name="{$field_name}"
value="residential"
data-ca-lite-checkout-field="{$field_name_helper}"
- data-ca-lite-checkout-element="{$element_name_helper}"
data-ca-lite-checkout-auto-save-on-change="true"
- data-ca-lite-checkout-last-value="{$field_value}"
{if !$field_value || $field_value == "residential"}checked{/if}
{$field.attributes|render_tag_attrs nofilter}
/>
@@ -170,9 +154,7 @@
name="{$field_name}"
value="commercial"
data-ca-lite-checkout-field="{$field_name_helper}"
- data-ca-lite-checkout-element="{$element_name_helper}"
data-ca-lite-checkout-auto-save-on-change="true"
- data-ca-lite-checkout-last-value="{$field_value}"
{if $field_value == "commercial"}checked{/if}
{$field.attributes|render_tag_attrs nofilter}
/>
@@ -186,9 +168,7 @@
name="{$field_name}"
value="{$field_value}"
data-ca-lite-checkout-field="{$field_name_helper}"
- data-ca-lite-checkout-element="{$element_name_helper}"
data-ca-lite-checkout-auto-save="true"
- data-ca-lite-checkout-last-value="{$field_value}"
autocomplete="{$field.autocomplete}"
aria-label="{$field.description}"
title="{$field.description}"
diff --git a/design/themes/responsive/templates/views/checkout/components/profile_fields/s_city_autocomplete.tpl b/design/themes/responsive/templates/views/checkout/components/profile_fields/s_city_autocomplete.tpl
index f03bd78d6f2..86ca1124257 100644
--- a/design/themes/responsive/templates/views/checkout/components/profile_fields/s_city_autocomplete.tpl
+++ b/design/themes/responsive/templates/views/checkout/components/profile_fields/s_city_autocomplete.tpl
@@ -36,6 +36,7 @@
id="litecheckout_zipcode"
data-ca-lite-checkout-last-value="{$zipcode}"
data-ca-lite-checkout-element="zipcode"
+ data-ca-lite-checkout-type="secondary"
value="{$zipcode}"
/>
diff --git a/js/addons/geo_maps/provider/yandex/maps.js b/js/addons/geo_maps/provider/yandex/maps.js
index 7f37a33fb39..241ed7ecccd 100644
--- a/js/addons/geo_maps/provider/yandex/maps.js
+++ b/js/addons/geo_maps/provider/yandex/maps.js
@@ -12,6 +12,10 @@
$.geoMapInitYandexApi(options)
.done(function () {
+ // Check if the map was removed when AJAX-requested.
+ if (!$container.length || !$.contains(document.documentElement, $container[0])) {
+ return;
+ }
self._initMap($container, options);
self._registerMapClickEvent($container);
diff --git a/js/tygh/checkout/lite_checkout.js b/js/tygh/checkout/lite_checkout.js
index f4392752f85..6a404826a85 100644
--- a/js/tygh/checkout/lite_checkout.js
+++ b/js/tygh/checkout/lite_checkout.js
@@ -35,7 +35,7 @@
$checkout = $jelm;
$country = methods.getElement('country');
$city = methods.getElement('city');
- $zipCode = methods.getElement('zipcode', false, true);
+ $zipCode = methods.getZipCode();
$autocompleteCity = methods.getElement('city-autocomplete');
$shippingMethods = methods.getElement('shipping-methods');
$userProfiles = methods.getElement('user-profiles');
@@ -46,6 +46,7 @@
methods.initPlainCityInput();
}
+ methods.initZipCode();
methods.bindAbandonedCartFieldsSaving();
methods.initMultipleProfileRoutines();
methods.initCustomValidation(methods.getElement('checkout-form'));
@@ -97,11 +98,6 @@
* So, when updating the shipping address, the checkout page must be redrawn completely.
*/
var isAddressField = addressFields.indexOf(fieldName) !== -1;
-
- if (isAddressField) {
- methods.lockShippingMethodSelector();
- }
-
methods.updateCustomerInfo($.noop, false, true, true, isAddressField);
});
},
@@ -222,7 +218,7 @@
var $elm = $(elm),
value;
if ($(elm).data('caLiteCheckoutElement')) {
- value = methods.getElement($(elm).data('caLiteCheckoutElement'), false, true).val();
+ value = methods.getElement($(elm).data('caLiteCheckoutElement')).val();
} else {
value = $elm.val();
}
@@ -359,7 +355,9 @@
setLocation: function(city, stateCode, state, zipcode) {
// update plain fields
$city.val(city);
- $zipCode.val(zipcode ? zipcode : '');
+ if ($zipCode.length) {
+ $zipCode.val(zipcode ? zipcode : '');
+ }
methods.getElement('state').val(stateCode ? stateCode : state);
// update autocomplete field
@@ -460,6 +458,7 @@
$city.val('');
$autocompleteCity.val('');
+ methods.lockShippingMethodSelector();
$autocompleteCity.focus();
}).on('keypress', function (e) {
e.preventDefault();
@@ -552,11 +551,10 @@
return;
}
- if (!$city.length) {
- methods.lockShippingMethodSelector();
- }
+ methods.lockShippingMethodSelector();
$city.val('');
+ $states.filter(':not(:disabled)').focus();
}).on('keypress', function (e) {
e.preventDefault();
});
@@ -564,13 +562,32 @@
$shippingMethods.on('click', function (e) {
methods.setLocationByPlainCityInput();
});
+ },
- $.ceEvent('on', 'ce.rebuild_states', function (context) {
- if (methods.getElement('state', true).length && methods.getElement('state').val() === '') {
- methods.getElement('state', false, true, true).focus();
- } else {
- methods.getElement('city', false, true, true).focus();
- }
+ getZipCode: function () {
+ const $zipCodes = $('[data-ca-lite-checkout-field="user_data.s_zipcode"]', $checkout);
+ let $zipCodePrimary = $();
+ let $zipCodeSecondary = $();
+
+ if ($zipCodes.length > 1) {
+ $zipCodePrimary = $zipCodes.filter(':not([data-ca-lite-checkout-type="secondary"])').first();
+ $zipCodeSecondary = $zipCodes.filter('[data-ca-lite-checkout-type="secondary"]').first();
+ $zipCodePrimary.data('caLiteCheckoutLastValue', $zipCodePrimary.val());
+ $zipCodeSecondary.remove();
+ } else if ($zipCodes.length === 1) {
+ $zipCodePrimary = $zipCodes;
+ }
+
+ return $zipCodePrimary;
+ },
+
+ initZipCode: function () {
+ if (!$zipCode.length) {
+ return;
+ }
+
+ $zipCode.on('input', function (e) {
+ methods.lockShippingMethodSelector();
});
},
@@ -583,16 +600,13 @@
city = $city.val(),
state = $state.val(),
country = $country.val(),
- zipCode = $zipCode.val(),
lastSelectedCity = $city.data('caLiteCheckoutLastValue'),
lastSelectedState = $state.data('caLiteCheckoutLastValue'),
- lastSelectedCountry = $country.data('caLiteCheckoutLastValue'),
- lastSelectedZipCode = $zipCode.data('caLiteCheckoutLastValue');
+ lastSelectedCountry = $country.data('caLiteCheckoutLastValue');
var isCityChanged = city !== lastSelectedCity,
isStateChanged = state !== lastSelectedState,
- isCountryChanged = country !== lastSelectedCountry,
- isZipCodeChanged = zipCode !== lastSelectedZipCode;
+ isCountryChanged = country !== lastSelectedCountry;
var stateCode = '';
if ($state.data('caLiteCheckoutIsStateCodeContainer')) {
@@ -602,8 +616,10 @@
methods.unlockShippingMethodSelector();
- if (isCityChanged || isStateChanged || isCountryChanged || isZipCodeChanged) {
- methods.setLocation(city, stateCode, state, zipCode);
+ if (isCityChanged || isStateChanged || isCountryChanged) {
+ methods.setLocation(city, stateCode, state);
+ } else if ($zipCode.length && ($zipCode.val() !== $zipCode.data('caLiteCheckoutLastValue'))) {
+ methods.setLocation(city, stateCode, state, $zipCode.val());
}
},
@@ -714,19 +730,13 @@
});
},
- getElement: function (role, getAll, getOne, isFirst) {
+ getElement: function (role, getAll) {
var selector = '[data-ca-lite-checkout-element="' + role + '"]';
if (getAll !== true) {
selector += ':not(:disabled)';
}
- var $elems = $(selector, $checkout);
-
- if (getOne) {
- $elems = (isFirst) ? $elems.first() : $elems.last();
- }
-
- return $elems;
+ return $(selector, $checkout);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment