<script>(function() {
// function to get GET variables from the address bar
function getParameterByName($from, $name) {
let match = RegExp(`[?&]` + $name + `=(?!=&)([^&]*)`).exec($from);
return match && decodeURIComponent(match[1].replace(/\+/g, ` `));
}
// start recording an array with site sorting data and GET variables upon detecting sort_by
let $from = window.location.href;
if (getParameterByName($from, "sort_by") !== null) {
let $hotengine_cookie_conv_to_get = [
{"sort_by": getParameterByName($from, "sort_by")},
{"order_by": getParameterByName($from, "order_by")},
{"order_by_param": getParameterByName($from, "order_by_param")},
{"shop_new_goods": getParameterByName($from, "shop_new_goods")},
{"shop_sale": getParameterByName($from, "shop_sale")},
{"shop_bestsellers": getParameterByName($from, "shop_bestsellers")},
{"shop_discount": getParameterByName($from, "shop_discount")},
{"shop_reduced_price": getParameterByName($from, "shop_reduced_price")},
{"sort_instock_priority": getParameterByName($from, "sort_instock_priority")},
{"price_from": getParameterByName($from, "price_from")},
{"price_to": getParameterByName($from, "price_to")},
{"NUM_ONPAGE": getParameterByName($from, "NUM_ONPAGE")},
{"smart_search": getParameterByName($from, "smart_search")},
{"search": getParameterByName($from, "search")},
];
// record Cookie with data in JSON format
document.cookie = `hotengine_cookie_conv_to_get=${JSON.stringify($hotengine_cookie_conv_to_get)}; path=/; max-age=31536000;`;
}
// to delete Cookie use document.cookie=`hotengine_cookie_conv_to_get=; path=/; max-age=0;`;
})();
</script>
В результаті, якщо відвідувач сортує товари, то з адресного рядка виймаються дані «
» та інші. Дані записуються в Cookie в json форматі. Після чого при відкритті сторінок надалі, сайт при виявленні Cookie «
», конвертує імена (індекси) масиву, в GET змінні з відповідними індексами та значеннями. Таким чином обравши сортування сайту один раз, відвідувач буде бачити її до тих пір, поки Cookie не буде змінено.