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

大家都知道ECShop会员退出登录同时会把已经加入购物车里的商品清空掉,如何实现会员退出登陆后不清空会员购物车中的商品了?下面可以通过ECSHOP网站开发中心官方技术提供的方法,做一个小小的修改即可实现会员退出登录后同时保留原购物车里面的商品不清空。大家可以测试一下我们官方保留会员购物车效果,当然,我们官方这种效果的基础上做了进一步的开发,会员更换IP,更换电脑操作系统,更换电脑均不影响会员保留在购物车中的商品,实现永久保留会员购物车中商品.

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);

}

}

至此全部修改完成,即可实现会员退出登录不清空购物车。

你可能感兴趣的:(ecshop会员退出登录后仍然保留购物车里的商品)