< span="">
< span="">
1. Id
2. goods_id Product ID
3. session_id Shopping Cart ID
4. GOODS_SN Product Code
5. Goods_name Product Name
6. Shop_price Commodity Mall Price
7. Goods_price Commodity Real Price (the difference with Shop_price is that when the discount, Shop_price is the price of the product before the discount, and Goods_price is after the discount)
8. Number of Goods_number
9. Weight Product Weight
Goods_attr product attributes (e.g. color, size)
Promote_code Promo code (for merchandising, strategy pattern identification code)
Is_promote Promo ID
STOCK_ID Stock ID
The database structure is probably like this. Of course, if there are other needs, such as merchandise rebate points, whether the product is a virtual product, whether the goods on behalf of the shipment, etc., can be added to the indicator.
2nd, this shopping cart requirements are not logged in the user can add products to the shopping cart, which is a very popular way recently, so in the shopping cart database design, there is no user_id this field, considering that the user is not logged under can also put the goods into the shopping cart.
Then identify the shopping cart in the end is which one user, is the need to use the session_id, is the user's corresponding shopping cart unique identification code. This code can be built in the constructor of the Cart object cart:
Java code
- /**
- * Shopping Cart type shopping method
- * website:www.jbxue.com
- * @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;
- }
There are pros and cons, the advantage of this design is that you can use the shopping cart without logging in, the advantage is that the two people share a computer, the shopping cart can not determine who is the product.
3rd, 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:
Java code
- /**
- * Add Item
- * website:www.jbxue.com
- */
- Public Function goodsaddaction ()
- {
- //Add product use GET request
- $goods _id = $this->_getparam (' goods_id '); //Product ID
- $goods _spec = $this->_getparam (' filter_name '); //Commodity attributes (color, size)
- $goods _number = $this->_getparam (' goods_number '); //Number of goods
- $promote _name = $this->_getparam (' promote_name ', ' Default '); //Promotion Strategy
- //Get Shopping cart instances
- $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 it out.
- $This->_showmessage (Bll_context::iserror ()? Bll_context::geterror (): ' Add to basket success! ', Bll_context::getrecirect ('/orderv2 '), 3);
- }
Line 15th of the previous code:
$cartB->goodsadd ($goods _id, $goods _spec, $goods _number, $promote _name);
This is the addition of the product operation function, which $promote_name is a promotion of the parameters, in particular, using the strategy model to choose which promotional strategy, I am prepared to discuss the next article specifically. As long as you know it is to add the basic information of this product, deposit into the shopping cart database.
Next is the second action:
Java code
- /**
- * Shopping list
- */
- Public Function indexaction ()
- {
- //Get Shopping cart instances
- $cartB = $this->_getcart ();
- //List all items in cart
- $This->view->goods_list = $cartB->goodsviewlist ();
- //Get a list of rule instances for displaying 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 the shopping cart
- $This->view->total_amount = $cartB->gettotalamount ();
- }
Here the first and second action must be separate, because the user can also not add merchandise direct point shopping cart.
Articles you may be interested in:
PHP Online Mall Shopping Cart code
PHP Shopping Cart Complete implementation code
PHP Shopping Cart feature Implementation code (introductory example)
PHP Shopping Cart class implementation code (Singleton mode)
PHP Shopping Cart class implementation code
PHP Shopping Cart code example
Implementation code for the PHP Shopping cart class
http://www.bkjia.com/PHPjc/636690.html www.bkjia.com true http://www.bkjia.com/PHPjc/636690.html techarticle 1. ID 2. GOODS_ID item ID 3. SESSION_ID Shopping Cart ID 4. GOODS_SN product Code 5. Goods_name Product name 6. Shop_price Commodity Store price 7. Goods_price Goods really Real selling price (with Sho ...