首页 > 网站 > 建站经验 > 正文

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

2024-04-25 20:32:08
字体:
来源:转载
供稿:网友

大家都知道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);

}

}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表