用户未登陆时,购物车物品保存到cookie

思路:key:goods_id-商品属性;

value:购买商品的数目count;

unserialize(cookie('cart')) :反序列化记录cart的cookie; 字符串->数组;

if(array_key_exists($key,$cart))  $cart[$key] += $goods_counts; :说明商品信息存在,直接添加数目;

else $cart[$key] = $goods_counts;

在把$cart数据写会cookie:  cookie('cart', serialize($cart));   数组->字符串 保存进cookie.

猜你喜欢

转载自blog.csdn.net/honkkki/article/details/82023406