因为之前做购物车做的redis。
购物车不仅仅可以存在服务端的redis中,也可以存在前端的cookie中
别忘记依赖。
jquery-1.12.1.min.js
jquery.cookie.js
这是我用的俩个依赖
//购物车
var Cart = function () {
this.Count = 0;
this.Total = 0;
this.Items = new Array();
};
//购物车集合对象
var CartItem = function () {
this.Id = 0;
this.Name = "";
this.Count = 0;
this.Price = 0;
};
//购物车操作
var CartHelper = function () {
this.cookieName = "{$member_id}_repast_cart";
this.Clear = function () {
var cart = new Cart();
this.Save(cart);
return cart;
};
//向购物车添加
this.Add = function (id, name, count, price) {
var cart = this.Read();
var index = this.Find(id);
if(count==0){
this.Del(id);
}else{
//如果ID已存在,覆盖数量
if