Creating applications or Shopping Cart shopping cart is always the most important part for web workers. With stormy growth of electronic commerce, the increasing number of website sales with all genres appear.
Creating applications or Shopping Cart shopping cart is always the most important part for web workers. With stormy growth of electronic commerce, the increasing number of website sales with all genres appear. In fact, when building a sales website, you do not need to do much programming, because there are so many open source support building an online store such as Magento, CS Cart, Presstashop ... .. But do What they do, if you can build yourself a shopping cart separately, then both can improve programming, while they can better understand the mechanism by which a sales website needs.
Today, in this article, I will be with you every step creates a simple shopping cart with PHP. And through this article, you can develop more advanced for a basket as the main standard for your website.
First, you need to create the following four files to Cart (shopping cart) their:
Config.php (database connectivity)
Index.php (page displays a list of products from a database)
Cart_update.php (updated basket)
View_cart.php (see the review cart before payment)
Okie, that's it, and now we will proceed step by step.
Step 1: Create a database
First of all, we need a data store of product information such as product name, product image ... sql following paragraph:
If you do not know how to use SQL statements to create, they can go to phpMyAdmin to create sql structure above. When creating the table (table) is done, you can add a list of products as shown in the following table:
Step 2: connecting database
Once we have the data stored product information, we will proceed with a data connection to display the screen. The config.php file that you open and copy the following code inside it:
You remember the value changes according to the notes that his next record offline.
Step 3: Display product information and shopping cart
Now is the time that we will show a list of products for sale,. Because we will use to store temporary information session cart, so the first thing to do is we have to activate the session. Open the index.php file and copy the following code to paste into it:
Index.php page will display two content, content 1 will list the product (in the middle) and the 2nd content displayed Cart (located right next door).
You copy this code and paste it in to the index.php file to display the product from the database:
The Shopping Cart:
Then copy and paste the following code to the index.php file to display cart:
Step 4: Update cart
Carts will be added and deleted function product is being put into the basket. When you click on "Add to Cart", the form will send a hidden value is the product code (product code) with the number (quantity) to Cart_update.php file through POST method. We will use the information sent to it to retrieve information from the database product. You copy the code below and paste it into Cart_update.php file. Each command has to notes, you can see the notes to understand the code better.
Step 5: Get an overview Carts
Now we will list all the products in the cart, the quantity, the price, and the total amount to be paid before the "bid". If you want to raise, in this section you can add tax and shipping ... You copy the following code to fileView_cart.php.
That's it then that you, to have a true basket, then there are many issues and details to be added, however, you need to master the basic steps shown in this lesson and, thereafter, may raise up as we wish. If you have any questions, do not hesitate to leave a message in the form of comments offline.