First, the database design of the shopping cart: 1. id2.goods _ id item ID3.session _ id shopping cart ID4.goods _ sn item code 5. goods_name product name 6. shop_price goods mall price 7. goods_price: the actual price of the product (the difference between shop_price and shop_price is that when the price is discounted, shop_price is the price of the product before the discount.
First, the database design of the shopping cart: 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 goods mall price 7. goods_price: the actual price of the product (the difference between shop_price and shop_price is that when the price is discounted, shop_price is the price of the product before the discount.
First, the database design of the shopping cart:
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
7. The real price of goods_price (the difference between shop_price and shop_price is that when the discount is made, shop_price is the price of the product before the discount, and goods_price is the price after the discount)
8. goods_number quantity
9. weight product weight
10. goods_attr product attributes (such as color and size)
11. promote_code: The Promotion Code (The rule pattern identification code for product promotion)
12. is_promote promotion ID
13. stock_id inventory ID
The database structure is like this. Of course, if there are other requirements, such as the product's rebate points, whether the product is a virtual product, whether the product is delivered on behalf of the other, you can add a new identifier.
Second, this shopping cart requires that you can add items to the shopping cart without logging on to the user. This is also a very popular method recently, so in the shopping cart database design, the user_id field is not added, because the user can also put the item into the shopping cart without logging in.
To identify which user the shopping cart is, session_id is used, which is the unique identifier of the user's corresponding shopping cart. This code can be generated in the Cart constructor of the shopping Cart object:
Java code
- /**
- * Shopping methods for shopping cart
- * Website: www.jbxue.com
- * @ Param string $ cart_id: ID of the shopping cart
- */
- 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 advantages and disadvantages in everything. The advantage of this design is that you can use the shopping cart without logging on. The disadvantage is that the two share a computer, and the shopping cart cannot determine which person the product is.
Third, add a product to the shopping cart.
Add a commodity to the shopping cart. Here, I think of it as two actions.
First Action: add the item to the shopping cart database.
The second action is to find and display all the items in the shopping cart.
The first action is:
Java code
- /**
- * Add product
- * Website: www.jbxue.com
- */
- Public function goodsAddAction ()
- {
- // Add product use get request
- $ Goods_id = $ this-> _ getParam ('goods _ id'); // item id
- $ Goods_spec = $ this-> _ getParam ('filter _ name'); // item attributes (color, size)
- $ Goods_number = $ this-> _ getParam ('goods _ number'); // number of items
- $ Promote_name = $ this-> _ getParam ('promote _ name', 'default'); // promotion policy
- // Get the shopping cart instance
- $ CartB = $ this-> _ getCart ();
- $ CartB-> goodsAdd ($ goods_id, $ goods_spec, $ goods_number, $ promote_name );
- // After the product is successfully added, go to the next step to find all the items in the shopping cart and display them.
- $ This-> _ showMessage (Bll_Context: isError ()? Bll_Context: getError (): 'added to the shopping basket! ', Bll_Context: getRecirect ('/orderv2 '), 3 );
- }
Line 2 of the code above:
$ CartB-> goodsAdd ($ goods_id, $ goods_spec, $ goods_number, $ promote_name );
The second action is:
Java 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 ();
- // Obtain 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 total amount of goods in the shopping cart
- $ This-> view-> total_amount = $ cartB-> getTotalAmount ();
- }
The first and second actions must be separated, because the user can directly click the shopping cart without adding the item.
Articles you may be interested in:
Php Online Shopping Mall Shopping Cart code
Complete php shopping cart implementation code
Php shopping cart function implementation code (Getting Started example)
Php shopping cart class implementation code (Singleton Mode)
Php shopping cart implementation code
Php shopping cart code example
Php shopping cart class implementation code