<script type="text/javascript" src="/modules/jquery.cookie/jquery.cookie.min.js"></script>
<script type="text/javascript"><!--
//функция определения GET переменных из адресной строки
function getParameterByName($from,$name){
let match = RegExp('[?&]' + $name + '=([^&]*)').exec($from);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}
$(function(){
//при обнаружении sort_by начинаем запись массива с данными, GET переменными сортировки сайта
let $from = window.location.href;
if(getParameterByName($from,"sort_by")!=undefined){
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") },
];
//записываем Cookie с данными в JSON формате
$.cookie("hotengine_cookie_conv_to_get", JSON.stringify($hotengine_cookie_conv_to_get), {expires: 365, path: "/"});
}
// для удаления Cookie используйте $.cookie("hotengine_cookie_conv_to_get", null, {expires: 0, path: "/"});
});
//-->
</script>
В результате, если посетитель сортирует товары, то из адресной строки вынимаются данные «sort_by», «order_by», «NUM_ONPAGE» и другие. Данные записываются в Cookie в json формате. После чего при открытии страниц в дальнейшем, сайт при обнаружении Cookie «hotengine_cookie_conv_to_get», конвертирует имена (индексы) массива, в GET переменные с соответствующими индексами и значениями. Таким образом выбрав сортировку сайта один раз, посетитель будет видеть ее до тех пор, пока Cookie не будет изменен.