Shopping Cart Tutorial Introduction

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 :
  1. A customer visit the site
  2. She browse the pages, clicking her way between categories
  3. View the product details that she found interesting
  4. Add products to shopping cart
  5. Checkout ( entering the shipping address, payment info )
  6. Leave ( hopefully to return another time )
Nothing complex here. The customer doesn’t need to register for an account. She just buy then leave.

Features

Okay, here are the shop features ( or maybe i should call this restrictions )
  1. 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.
  2. 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.
  3. 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 :
Shopping Cart File Organization
The plaincart/library directory contain :
  • 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
The plaincart/include contain :
  • 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 )
The plaincart/include/paypal directory contain :
  • 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
The plaincart/admin folder will contain all the admin files.You can see that admin folder also contain include and library folder. These will contain specific library files for the admin pages
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
If you don’t have these ready check out this tutorial to install them : Installing Apache PHP & MySQL

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

Artikel Terkait Joomla ,Web