ecshop会员退出登录保留购物车里的商品

大家都知道ECShop会员退出登录同时会把已经加入购物车里的商品清空掉,通过本内容做修改即可实现会员退出登录同时保留原购物车里面的商品不清空。

1. 打开includes\cls_session.php文件
搜索如下代码:
$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");

2. 打开includes\lib_main.php文件
搜索如下代码:
function update_user_info()
在改函数内部末尾添加如下代码:
    /* 更新用户购物车,退出不清空购物车 */
    $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);
		}
    }
至此全部修改完成,即可实现会员退出登录不清空购物车

本文原创地址:https://www.ecshop.cx/article-127.html
版权所有 © 转载时必须以链接形式注明出处!

觉得本文对您有用,想收藏下来!方法很简单:请点击-〉
我们一直坚持白天工作、晚上熬夜更新资源,付出了巨大的精力和时间,其中的辛酸难以言述。

实时购买动态 ×

匿名网友 在 2019-07-07 购买了 ECSHOP一个账号同时只能一个人登录【实现前者踢下线功能】