- /**
- * Shopping Cart Type 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 Code3rd, add a product to the shopping cart. Add a product to the shopping cart, where I think of it as a two action. First action: Add items to the shopping cart database. Second action: Find all items in the shopping cart and show them. First is the first action: The code is as follows:
- /**
- * Add Item
- */
- Public Function goodsaddaction ()
- {
- Add a product using GET request
- $goods _id = $this->_getparam (' goods_id ');//commodity ID
- $goods _spec = $this->_getparam (' filter_name ');//commodity properties (color, size)
- $goods _number = $this->_getparam (' goods_number ');//Quantity of goods
- $promote _name = $this->_getparam (' promote_name ', ' Default ');//Promotion Strategy
- Get a shopping cart instance
- $cartB = $this->_getcart ();
- $cartB->goodsadd ($goods _id, $goods _spec, $goods _number, $promote _name);
- Add success, jump to Next, find all items in cart and show them out.
- $this->_showmessage (Bll_context::iserror ()? Bll_context::geterror (): ' Add to basket success! ', Bll_context::getrecirect ('/orderv2 '), 3);
- }
- ?>
Copy CodeLine 15th of the previous code:
- /**
- * Shopping List
- */
- Public Function indexaction ()
- {
- Get a shopping cart instance
- $cartB = $this->_getcart ();
- List all items in your shopping cart
- $this->view->goods_list = $cartB->goodsviewlist ();
- Gets a 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 total amount of merchandise in your shopping cart
- $this->view->total_amount = $cartB->gettotalamount ();
- }
- ?>
Copy CodeIn the above code, the first and second actions must be separate, allowing no items to be added directly to the shopping cart. That's all, let's hope that we have a little bit of inspiration, in the next satisfaction. |