Created
September 30, 2020 09:06
-
-
Save ichaykin/7e66d94081245da38555a6fae77ccf48 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/app/controllers/backend/init.php b/app/controllers/backend/init.php | |
index f00a4eb..f468e3b 100644 | |
--- a/app/controllers/backend/init.php | |
+++ b/app/controllers/backend/init.php | |
@@ -276,6 +276,7 @@ Tygh::$app['view']->assign('store_mode', $store_mode); | |
Tygh::$app['view']->assign('product_state_suffix', $product_state_suffix); | |
Tygh::$app['view']->assign('store_mode_number_of_storefronts', count(fn_get_all_companies_ids())); | |
Tygh::$app['view']->assign('store_mode_allowed_number_of_storefronts', fn_get_storage_data('allowed_number_of_stores')); | |
+Tygh::$app['view']->assign('hash_of_available_countries', fn_get_hash_of_available_countries()); | |
if (!Registry::get('runtime.company_id') && Registry::get('runtime.controller') != 'auth' && !empty($license_errors) && empty($store_mode_errors)) { | |
Tygh::$app['view']->assign('show_license_errors_dialog', true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/app/controllers/frontend/init.php b/app/controllers/frontend/init.php | |
index cb7c19c..5174d55 100644 | |
--- a/app/controllers/frontend/init.php | |
+++ b/app/controllers/frontend/init.php | |
@@ -139,6 +139,7 @@ if (!empty($dynamic_object_scheme) && !empty($_REQUEST[$dynamic_object_scheme['k | |
Tygh::$app['view']->assign('location_data', Location::instance()->get($dispatch, $dynamic_object, CART_LANGUAGE)); | |
Tygh::$app['view']->assign('layout_data', Registry::get('runtime.layout')); | |
Tygh::$app['view']->assign('current_mode', fn_get_current_mode($_REQUEST)); | |
+Tygh::$app['view']->assign('hash_of_available_countries', fn_get_hash_of_available_countries()); | |
// Init cart if not set | |
if (empty(Tygh::$app['session']['cart'])) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/app/functions/fn.locations.php b/app/functions/fn.locations.php | |
index 4b315bf..2f287db 100644 | |
--- a/app/functions/fn.locations.php | |
+++ b/app/functions/fn.locations.php | |
@@ -776,3 +776,24 @@ function fn_destination_get_states($lang_code) | |
return $states; | |
} | |
+ | |
+/** | |
+ * Returns a hash of available countries. | |
+ * | |
+ * @return string | |
+ * | |
+ * @internal | |
+ */ | |
+function fn_get_hash_of_available_countries() | |
+{ | |
+ Registry::registerCache('available_countries_hash', ['countries'], Registry::cacheLevel('static')); | |
+ | |
+ if (Registry::isExist('available_countries_hash')) { | |
+ $avail_countries_hash = Registry::get('available_countries_hash'); | |
+ } else { | |
+ $avail_countries_hash = md5(json_encode(fn_get_simple_countries(true))); | |
+ Registry::set('available_countries_hash', $avail_countries_hash); | |
+ } | |
+ | |
+ return $avail_countries_hash; | |
+} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/design/backend/templates/common/scripts.tpl b/design/backend/templates/common/scripts.tpl | |
index 568471c..4b1939c 100644 | |
--- a/design/backend/templates/common/scripts.tpl | |
+++ b/design/backend/templates/common/scripts.tpl | |
@@ -141,7 +141,8 @@ | |
title: '{$addon_permissions_text.title|escape:javascript nofilter}', | |
text: '{$smarty.capture.promo_data|escape:javascript nofilter}' | |
}, | |
- phone_validation_mode: '{$settings.Appearance.phone_validation_mode}' | |
+ phone_validation_mode: '{$settings.Appearance.phone_validation_mode}', | |
+ hash_of_available_countries: '{$hash_of_available_countries}' | |
}); | |
$.extend(_, { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/design/themes/responsive/templates/common/scripts.tpl b/design/themes/responsive/templates/common/scripts.tpl | |
index f490e0a..fe6d73d 100644 | |
--- a/design/themes/responsive/templates/common/scripts.tpl | |
+++ b/design/themes/responsive/templates/common/scripts.tpl | |
@@ -122,7 +122,8 @@ | |
current_url: '{$config.current_url|fn_url|escape:javascript nofilter}', | |
current_host: '{$config.current_host|escape:javascript nofilter}', | |
init_context: '{$smarty.request.init_context|escape:javascript nofilter}', | |
- phone_validation_mode: '{$settings.Appearance.phone_validation_mode}' | |
+ phone_validation_mode: '{$settings.Appearance.phone_validation_mode}', | |
+ hash_of_available_countries: '{$hash_of_available_countries}' | |
}); | |
{if $live_editor_objects} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/js/tygh/phone_mask.js b/js/tygh/phone_mask.js | |
index 69322b6..9063176 100644 | |
--- a/js/tygh/phone_mask.js | |
+++ b/js/tygh/phone_mask.js | |
@@ -119,15 +119,23 @@ | |
function loadPhoneMasks() | |
{ | |
- var raw_phone_masks = window.localStorage.getItem('phoneMasks'), | |
- phone_masks, | |
+ var oldHashOfAvailableCountries = window.localStorage.getItem('availableCountriesHash'), | |
+ newHashOfAvailableCountries = _.hash_of_available_countries, | |
+ rawPhoneMasks = window.localStorage.getItem('phoneMasks'), | |
+ phoneMasks, | |
d = $.Deferred(); | |
- if (raw_phone_masks) { | |
- phone_masks = JSON.parse(raw_phone_masks); | |
+ if (rawPhoneMasks) { | |
+ phoneMasks = JSON.parse(rawPhoneMasks); | |
} | |
- if (!phone_masks) { | |
+ if ( | |
+ !phoneMasks | |
+ || ( | |
+ newHashOfAvailableCountries !== undefined | |
+ && oldHashOfAvailableCountries !== newHashOfAvailableCountries | |
+ ) | |
+ ) { | |
$.ceAjax('request', fn_url('phone_masks.get_masks'), { | |
method: 'get', | |
caching: false, | |
@@ -139,13 +147,13 @@ | |
$.ceEvent('trigger', 'ce.phone_masks.masks_loaded', [response]); | |
- phone_masks = Object.keys(response.phone_mask_codes).map(function (key) { | |
+ phoneMasks = Object.keys(response.phone_mask_codes).map(function (key) { | |
return response.phone_mask_codes[key]; | |
}); | |
- window.localStorage.setItem('phoneMasks', JSON.stringify(phone_masks)); | |
+ window.localStorage.setItem('phoneMasks', JSON.stringify(phoneMasks)); | |
- d.resolve(phone_masks); | |
+ d.resolve(phoneMasks); | |
}, | |
repeat_on_error: false, | |
hidden: true, | |
@@ -160,8 +168,10 @@ | |
d.reject(); | |
} | |
}); | |
+ | |
+ window.localStorage.setItem('availableCountriesHash', newHashOfAvailableCountries); | |
} else { | |
- d.resolve(phone_masks); | |
+ d.resolve(phoneMasks); | |
} | |
return d.promise(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment