您现在的位置是: 首页 > 技术分享 >
Ecshop退出登录保存购物车商品
引导语:Ecshop 用户登录后,将喜欢的商品加入购物车,退出重新登录后,购物车的商品被清空了。下面的内容就是保存原购物车的商品不清空。
1.打开includes - > cls_session.php 文件,搜索如下代码,大概267行
$this->db->query('DELETE FROM ' . $GLOBALS['ecs']->table('cart') . " WHERE session_id = '$this->session_id');
修改为
$this->db->query('DELETE FROM ' . $GLOBALS['ecs']->table('cart') . " WHERE session_id = '$this->session_id' AND user_id = 0");
打开includes -> lib_main.php文件
搜索function update_user_info()这个方法,大概19行,在该函数内部末尾添加如下代码
/* 更新用户购物车,退出不清空购物车 */ $sql = "UPDATE " .$GLOBALS['ecs']->table('cart'). " SET". " user_id = '" . $_SESSION['user_id'] . "'". " WHERE session_id = '" . SESS_ID . "'"; $GLOBALS['db']->query($sql); $sql = "UPDATE " . $GLOBALS['ecs']->table('cart') . " SET". " session_id = '" . SESS_ID . "'". " WHERE user_id = '" . $_SESSION['user_id'] . "'"; $GLOBALS['db']->query($sql); /* 删除购物车中已下架的商品 */ $sql = "SELECT DISTINCT(c.goods_id) FROM " .$GLOBALS['ecs']->table('cart'). " AS c left JOIN " .$GLOBALS['ecs']->table('goods'). " AS g on c.goods_id = g.goods_id WHERE g.is_on_sale = 0 AND c.user_id = '" . $_SESSION['user_id'] . "'"; $data = $GLOBALS['db'] ->getAll($sql); if($data){ foreach ($data as $k=>$v){ $sql = "DELETE FROM " .$GLOBALS['ecs']->table('cart'). " WHERE goods_id = '" . $v['goods_id'] . "'"; $GLOBALS['db'] -> query($sql); } }
分享:
上一篇: Ecshop商品详情添加加减按钮