復(fù)制代碼 代碼如下:
/**
* 購物車類購物方法
* @param string $cart_id 購物車ID
*/
public function __construct()
{
Zend_Session::start();
$this->_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;
}
復(fù)制代碼 代碼如下:
/**
* 添加商品
*/
public function goodsAddAction()
{
// 添加商品使用get請求
$goods_id = $this->_getParam('goods_id');//商品ID
$goods_spec = $this->_getParam('filter_name');//商品屬性(顏色,尺碼)
$goods_number = $this->_getParam('goods_number');//商品數(shù)量
$promote_name = $this->_getParam('promote_name', 'Default');//促銷策略
//獲取購物車實例
$cartB = $this->_getCart();
$cartB->goodsAdd($goods_id, $goods_spec, $goods_number, $promote_name);
//添加成功,跳轉(zhuǎn)到下一步,查找購物車所有商品,并顯示出來。
$this->_showMessage(Bll_Context::isError() ? Bll_Context::getError() : '添加到購物籃成功!', Bll_Context::getRecirect('/orderv2'), 3);
}
復(fù)制代碼 代碼如下:
/**
* 購物列表
*/
public function indexAction()
{
//獲取購物車實例
$cartB = $this->_getCart();
//列出購物車內(nèi)所有商品
$this->view->goods_list = $cartB->goodsViewList();
//獲取用于顯示規(guī)則消息的規(guī)則實例列表
$this->view->tips = $cartB->goodsTipRules();
//購物車內(nèi)商品總數(shù)量
$this->view->total_number = $cartB->getTotalGoodsNumber();
//獲取購物車內(nèi)商品總貨額
$this->view->total_amount = $cartB->getTotalAmount();
}
這里第一個和第二個動作必須是要分開的,因為用戶也可以不添加商品直接點購物車。
下面是效果圖:
第一次發(fā)帖,有什么不足,不清楚的,還請見諒。歡迎討論!
新聞熱點
疑難解答