Работа cookie
Здравствуйте!
Суть такова, кладем в корзину продукт и записываем в куки. Далее обноваляем старницу, читаем куки записываем значение в переменные (все тоже все окей). Переходим в другую категорию кладем в корзину товар и почему-то в этот момент корзина обнуляется (т.е. было 5 шт. 23441 руб., а стало 1шт. 200 руб.) Подскажите, пожалуйста, ЧТО НЕ ТАК??? var productPrice = get_cookie("productPrice") ? 0 : get_cookie("productPrice"); var productCount = get_cookie("productCount") ? 0 : get_cookie("productCount"); function setBasketProduct(id, count, price){ productCount += count; productPrice += price; document.getElementById("productCount").innerHTML = productCount; document.getElementById("productPrice").innerHTML = productPrice; var times = new Date(); set_cookie ( "product", get_cookie("product") + ", " + id + "-" + count + "-" + price, times.getFullYear(), times.getMonth(), (times.getDay()+1), "/", "", "" ); set_cookie ( "productCount", productCount, times.getFullYear(), times.getMonth(), (times.getDay()+1), "/", "", "" ); set_cookie ( "productPrice", productPrice, times.getFullYear(), times.getMonth(), (times.getDay()+1), "/", "", "" ); } |
Больше всего интересует строчки:
set_cookie ( "productCount", productCount, times.getFullYear(), times.getMonth(), (times.getDay()+1), "/", "", "" ); set_cookie ( "productPrice", productPrice, times.getFullYear(), times.getMonth(), (times.getDay()+1), "/", "", "" ); положили в корзину 5шт. 2100 руб., куки отлично записались. Далее обновляем стараницу (но при этом куки сохранены), кладем опять в карзину и в куках видем не 6шт. 5000 руб., а 1шт. 300 руб. |
Javascript сам старается переобразовывать тип данных, оно видно:
var productPrice = Number(get_cookie("productPrice")); var productCount = Number(get_cookie("productCount")); Проблема решена |
Часовой пояс GMT +3, время: 09:09. |