-
- /**
- * Shopping cart shopping method
- * @param string $cart_id Shopping cart 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;
- }
- ?>
-
Copy code
The third point, Add an item to your cart.
Adding an item to the shopping cart, here, I think of it as two actions.
The first action: add products to the shopping cart database.
Second action: Find all the items in the shopping cart and display them.
First, the first action:
The code is as follows:
-
- /**
- * Add product
- */
- public function goodsAddAction()
- {
- // Add goods using get request
- $goods_id = $this->_getParam('goods_id') ;//Product ID
- $goods_spec = $this->_getParam('filter_name');//Product attributes (color, size)
- $goods_number = $this->_getParam('goods_number');//Quantity of goods
- $promote_name = $this->_getParam('promote_name', 'Default');//Promotion strategy
- //Get shopping cart instance
- $cartB = $this->_getCart();
- $cartB-> goodsAdd($goods_id, $goods_spec, $goods_number, $promote_name);
- //Added successfully, jump to the next step, find all the goods in the shopping cart, and display them.
- $this->_showMessage(Bll_Context::isError() ? Bll_Context::getError() : 'Add to shopping basket successfully!', Bll_Context::getRecirect('/orderv2'), 3);
- }
- ?> ;
-
Copy code
Line 15 of the above code:
-
- /**
- * Shopping list
- */
- public function indexAction()
- {
- //Get the shopping cart instance
- $cartB = $this->_getCart();
- // List all items in the shopping cart
- $this->view->goods_list = $cartB->goodsViewList();
- //Get the list of rule instances used to display rule messages
- $this->view-> ;tips = $cartB->goodsTipRules();
- //Total number of items in the shopping cart
- $this->view->total_number = $cartB->getTotalGoodsNumber();
- //Get the items in the shopping cart Total amount
- $this->view->total_amount = $cartB->getTotalAmount();
- }
- ?>
-
Copy code
Among the above codes, the first and second The actions must be separated, allowing you to click the shopping cart directly without adding products.
That’s it, let’s throw some ideas into the discussion, I hope it can inspire you a little bit, I’ll be satisfied with this.
|