修改ecshop购物车退出后保留购物车购买的商品
2009-07-27 18:06 来源:www.chinab4c.com 作者:ecshop专家
最近很多做电子商务的朋友,都反映说ecshop购物车不是很好用。有时候特定的需求下,需要将购买的物品保留,或者当会员登陆买东西之后,不小心关闭浏览器,或者是退出的时候,还可以让商品保留在购物车,如果下次登陆,还可以看到购物车的产品.
首先,在没有登陆的时候,购物品车表cart中,user_id为空,所以当登陆的时候,可以将这个值写为用户的id,然后,当退出的时候,删除购物车的条件也严格一些,当有user_id不为空的时候,就不删除,当下次登陆的时候,将上次user_id下的session_id修改为当前登陆的session_id,如果这次也购买了该产品,那么你就将以前的产品数量加到当前该产品数量只下,然后删除之前购买的产品,从cart表中,这样就实现了购物车在退出的情况下,只要登陆的时候购买的产品,都可以保留下来.
1: 修改includes/cls_session.php中的 destroy_session()函数
$this->db->query('DELETE FROM ' . $GLOBALS['ecs']->table('cart') . " WHERE session_id = '$this->session_id' and user_id =''");
2:lib_mian.php文件中的update_user_info()函数
$sql = "update ".$GLOBALS['ecs']->table('cart')." set user_id =".$_SESSION['user_id']." where session_id = '".SESS_ID."'";
$GLOBALS['db'] -> query($sql);
$sql1 = "update ".$GLOBALS['ecs']->table('cart')." set session_id ='".SESS_ID."' where user_id = '".$_SESSION['user_id']."'";
$GLOBALS['db'] -> query($sql1);
$re = $GLOBALS['db'] -> getAll("select *,sum(goods_number) as goods_number from ".$GLOBALS['ecs']->table('cart')." where user_id = '{$_SESSION['user_id']}' and session_id = '".SESS_ID."' group by goods_id");
if($re){
foreach ($re as $k => $v){
$sql = "update ".$GLOBALS['ecs']->table('cart'). " set goods_number = ".$v['goods_number']." where rec_id = ".$v['rec_id'];
$GLOBALS['db'] -> query($sql);
$sql = "delete from ".$GLOBALS['ecs']->table('cart')." where rec_id <> {$v['rec_id']} and user_id = '{$_SESSION['user_id']}' and session_id = '".SESS_ID."' and goods_id = ".$v['goods_id'];
$GLOBALS['db'] -> query($sql);
}
}
//如果是缺货的商品。要删除
$cart_in = $GLOBALS['db']-> getAll("select * from ".$GLOBALS['ecs']->table('cart')." where session_id ='".SESS_ID."'");
if( $cart_in){
foreach ($cart_in as $k => $v){
$c = $GLOBALS['db'] -> getOne("select goods_number from ".$GLOBALS['ecs']->table('goods')." where goods_id = ".$v[goods_id]." and is_on_sale =1");
if($c){
}else{
if($v[rec_id]){
$GLOBALS['db'] -> query("delete from ".$GLOBALS['ecs']->table('cart')." where rec_id = ".$v['rec_id']);
}
}
}
}
4:
120 行处的
- setcookie($this->session_name, $this->session_id . $this->gen_session_key($this->session_id), 0, $this->session_cookie_path, $this->session_cookie_domain, $this->session_cookie_secure);
更改为
- if($this->session_name=='ECS_ID')
- {
- setcookie($this->session_name, $this->session_id . $this->gen_session_key($this->session_id), time()+30000000, $this->session_cookie_path, $this->session_cookie_domain, $this->session_cookie_secure);
- }
- else
- {
- setcookie($this->session_name, $this->session_id . $this->gen_session_key($this->session_id), 0, $this->session_cookie_path, $this->session_cookie_domain, $this->session_cookie_secure);
- }
这样就可以实现了。
相关文章:
来源:中国B4C电子商务
上海租车
最近更新
常用插件
- ecshop后台手动发送订单信
ecshop后台手动发送订单信息短信插件,这个插件非常有用,如果你的货...
- ecshop2.7.0utf给属性增加库存
插件介绍:本插件适合ecshop2.7.0的utf8编码对商品的属性进行库存管理...
- ecsho成本利润统计分析插件
最近在二次开发ecshop过程中,很多朋友要求一款分析 ecshop成本和利润插...
- ecshop 订单商品列表显示查
本插件可以将ecshop中所有的订单里面产品信息,按照产品和订单的关系...
- ecshop分类/频道下flash
ecshop分类/频道下flash,这个的功能是非常有用的。ecshop首页flash这个功能...



