PHP Online Mall Shopping Cart design Code _php Tutorial

Source: Internet
Author: User
Tags php online

< 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
  1. /**
  2. * Shopping Cart type shopping method
  3. * website:www.jbxue.com
  4. * @param string $cart _id shopping Cart ID
  5. */
  6. Public Function __construct ()
  7. {
  8. Zend_session::start ();
  9. $This->_session = new zend_session_namespace (' Shopcart ');
  10. if (!isset ($this->_session->session_id))
  11. {
  12. $This->_session->session_id = MD5 (Uniqid (Mt_rand (), true));
  13. $This->_session->info = Array ();
  14. }
  15. $This->_cart_id = $this->_session->session_id;
  16. }


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
  1. /**
  2. * Add Item
  3. * website:www.jbxue.com
  4. */
  5. Public Function goodsaddaction ()
  6. {
  7. //Add product use GET request
  8. $goods _id = $this->_getparam (' goods_id '); //Product ID
  9. $goods _spec = $this->_getparam (' filter_name '); //Commodity attributes (color, size)
  10. $goods _number = $this->_getparam (' goods_number '); //Number of goods
  11. $promote _name = $this->_getparam (' promote_name ', ' Default '); //Promotion Strategy
  12. //Get Shopping cart instances
  13. $cartB = $this->_getcart ();
  14. $cartB->goodsadd ($goods _id, $goods _spec, $goods _number, $promote _name);
  15. //Add success, jump to Next, find all items in cart and show it out.
  16. $This->_showmessage (Bll_context::iserror ()? Bll_context::geterror (): ' Add to basket success! ', Bll_context::getrecirect ('/orderv2 '), 3);
  17. }



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
  1. /**
  2. * Shopping list
  3. */
  4. Public Function indexaction ()
  5. {
  6. //Get Shopping cart instances
  7. $cartB = $this->_getcart ();
  8. //List all items in cart
  9. $This->view->goods_list = $cartB->goodsviewlist ();
  10. //Get a list of rule instances for displaying rule messages
  11. $This->view->tips = $cartB->goodstiprules ();
  12. //Total number of items in the shopping cart
  13. $This->view->total_number = $cartB->gettotalgoodsnumber ();
  14. //Get the total amount of merchandise in the shopping cart
  15. $This->view->total_amount = $cartB->gettotalamount ();
  16. }


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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.