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 is the selling price of the goods in the mall
7. goods_price is the real selling price of the goods (the difference from shop_price is that when there is a discount, shop_price is the selling price of the goods before the discount, while goods_price is after the discount)
8. goods_number quantity
9. weight product weight
10. goods_attr product attributes (such as color, size)
11. promote_code promotion code (strategy pattern identification code for product promotion)
12. is_promote promotion ID
13. stock_id Stock ID
The database structure is roughly like this. Of course, if there are other needs, such as rebate points for the product, whether the product is a virtual product, whether the product is shipped on behalf of others, etc., you can add additional identifiers.
Second point, this shopping cart requirement is that the user can add items to the shopping cart without logging in. This is also a very popular method recently, so in the shopping cart database design, it is The user_id field is not added, considering that users can put products into the shopping cart even if they are not logged in.
So to identify which user the shopping cart belongs to, you need to use session_id, which is the unique identification code of the user's corresponding shopping cart. The generated code can be placed in the constructor of the shopping cart object Cart:
Everything has advantages and disadvantages. The advantage of this design is that you can use the shopping cart without logging in; the disadvantage is that two people share a computer, and the shopping cart cannot determine who owns the product.
The third point is to add an item to the shopping cart.
Add 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 is the first action:
Line 15 of the above code:
$cartB->goodsAdd($goods_id, $goods_spec, $goods_number, $promote_name);
This is the add product operation function, here The $promote_name is a parameter of promotion. Specifically, it uses strategy mode to select which promotion strategy to use. I plan to discuss it in detail in the next article. All you need to know here is to add the basic information of this product and store it in the shopping cart database.
The second step is the second action:
The first and second actions here must be separated, because the user can also click the shopping cart directly without adding products.
Articles you may be interested in:
php online mall shopping cart code
php shopping cart complete implementation code
php shopping cart function implementation code (entry example)
php shopping cart class implementation code (single case mode)
php Shopping cart class implementation code
php shopping cart code example
php shopping cart class implementation code