您好,欢迎访问一九零五行业门户网

php网上商城购物车代码一例

_session = new zend_session_namespace('shopcart');if(!isset($this->_session->session_id)){$this->_session->session_id = md5(uniqid(mt_rand(), true));$this->_session->info = array();}$this->_cart_id = $this->_session->session_id;}?>
复制代码
第三点,添加一个商品到购物车。添加一个商品到购物车,在这里,我把它想成是两个动作。第一个动作:添加商品到购物车数据库里面。第二个动作:查找购物车所有商品,并显示出来。首先是第一个动作:
代码如下:
_getparam('goods_id');//商品id$goods_spec = $this->_getparam('filter_name');//商品属性(颜色,尺码)$goods_number = $this->_getparam('goods_number');//商品数量$promote_name = $this->_getparam('promote_name', 'default');//促销策略//获取购物车实例$cartb = $this->_getcart();$cartb->goodsadd($goods_id, $goods_spec, $goods_number, $promote_name);//添加成功,跳转到下一步,查找购物车所有商品,并显示出来。$this->_showmessage(bll_context::iserror() ? bll_context::geterror() : '添加到购物篮成功!', bll_context::getrecirect('/orderv2'), 3);}?>
复制代码
上段代码第15行:
_getcart();//列出购物车内所有商品$this->view->goods_list = $cartb->goodsviewlist();//获取用于显示规则消息的规则实例列表$this->view->tips = $cartb->goodstiprules();//购物车内商品总数量$this->view->total_number = $cartb->gettotalgoodsnumber();//获取购物车内商品总货额$this->view->total_amount = $cartb->gettotalamount();}?>
复制代码
以上代码中,第一个和第二个动作必须是要分开的,允许不添加商品直接点购物车。就是这些了,抛砖引玉吧,希望对大家有些许的启发,在下就满足了。
其它类似信息

推荐信息