he online shop we’re makin here is a basic one without any
sophisticated features and stuff. The shop has
admin pages ( where the shop admin can create categories, add products, etc ) and the shopper pages ( a.k.a the shop itself ) where all the shopping process takes place. You will learn more about them in subsequent pages.
By the way, i did call this tutorial as a shopping cart tutorial but actually we’re building an online shop ( a really simple one ). The shopping cart is just part of the shop. But because the term ‘shopping cart’ is already common to define an online shop solution i just use it instead of naming this site a ‘PHP MySQL Online Shop Tutorial’.
I have to assume that you already know about PHP and MySQL so i won’t explain every code in detail. The codes are not too complicated though, i’m sure you can understand it. I suggest you download the code first so you can run it on your computer. That way it’s easier for you to understand this tutorial
If you don’t want to download the code that’s fine but make sure you take a look at the demo site, this is what our shopping cart willl look like.
After you browse around you will see that the basic flow of our shop is :
admin pages ( where the shop admin can create categories, add products, etc ) and the shopper pages ( a.k.a the shop itself ) where all the shopping process takes place. You will learn more about them in subsequent pages.
By the way, i did call this tutorial as a shopping cart tutorial but actually we’re building an online shop ( a really simple one ). The shopping cart is just part of the shop. But because the term ‘shopping cart’ is already common to define an online shop solution i just use it instead of naming this site a ‘PHP MySQL Online Shop Tutorial’.
I have to assume that you already know about PHP and MySQL so i won’t explain every code in detail. The codes are not too complicated though, i’m sure you can understand it. I suggest you download the code first so you can run it on your computer. That way it’s easier for you to understand this tutorial
If you don’t want to download the code that’s fine but make sure you take a look at the demo site, this is what our shopping cart willl look like.
After you browse around you will see that the basic flow of our shop is :
- A customer visit the site
- She browse the pages, clicking her way between categories
- View the product details that she found interesting
- Add products to shopping cart
- Checkout ( entering the shipping address, payment info )
- Leave ( hopefully to return another time )
Features
Okay, here are the shop features ( or maybe i should call this restrictions )- Flat shipping cost.
No complex shipping calculation for this shop right now and i don’t have any plan to change this in near future. - Payment options including COD ( cash on delivery ) and Paypal
For now this shop can only handle COD and payment through Paypal IPN. The reason i pick paypal is because they provide excellent resource for developers so i can test the payment process easily. - Configurable image and thumbnail size
You can restrict the product image width from the config file. You can also set the thumbnail width you want for all product images that you upload.
File Organization
The files in our shop will be organized like this :
The plaincart/library directory contain :
All images required in our shop will be put in plaincart/images directory. The category and product images are put in the category and product sub-folder respectively.
First, open the php.ini file using a text editor ( notepad is okay ) and search for this line of code :
extension=php_gd2.dll
If you see that code preceded by a semicolon ( ; ) that means GD library is not enabled yet. Remove the semicolon to enable GD and then restart the web server ( apache ) for the changes to take effect.
I really hope this shopping cart tutorial is useful for you. Now to take the first step, let’s start with the database design
- config.php : this is the main configuration file for our shop
- category-functions.php :functions required for fetching the categories
- product-functions.php : contain product related functions
- cart-functions.php : shopping cart specific functions
- checkout-functions.php : checkout processes are in here
- common.php : common functions required for the shop and admin pages
- database.php : contain the database abstraction functions
- header.php
The shop common header. - top.php
You can place your shop banner here. - footer.php
Common footer, display the shop address, phone number and email. You can add more information here when needed. - shop.css
Style sheet file for our shop - leftNav.php
The left navigation you see on the shop - categoryList.php
Show the top categories we have - productList.php
Show the products in certain category - productDetail.php
You know what this is for, right ? - miniCart.php
Shown on the right portion of the shop pages, it shows the products in the shoping cart. - shippingAndPaymentInfo.php
The form to enter shipping and payment info ( step 1 of checkout ) - checkoutConfirmation.php
Show the order items, shipping & payment info ( step 2 of checkout )
- paypal.inc.php
The configuration file for the paypal payment module - ipn.php
The script that process payment verification - payment.php
Contain the form that submit the payment information from this website to paypal website
All images required in our shop will be put in plaincart/images directory. The category and product images are put in the category and product sub-folder respectively.
The Requirements
For this tutorial i’m using these :- Apache 2
- PHP 4.3.10 with GD ( graphics library ) support ( you can also use lower version but >= 4.3.7 )
- MySQL 4
What Configurations You Will Need
Database Configuration
When you install the shopping cart script you will need to modify library/config.php. You need to change the database connection info ( database host, username, password and name ) according to your own configurations.Enabling GD Support
The next thing you may need to do is to enable the GD support. This is usually enabled by default by web hosting company but in case you test it on your own computer you may need to enable it manually.First, open the php.ini file using a text editor ( notepad is okay ) and search for this line of code :
extension=php_gd2.dll
If you see that code preceded by a semicolon ( ; ) that means GD library is not enabled yet. Remove the semicolon to enable GD and then restart the web server ( apache ) for the changes to take effect.
I really hope this shopping cart tutorial is useful for you. Now to take the first step, let’s start with the database design