This site is a self-contained low down on what's going on in my life, what I'm working on, what I'm thinking about, and how I'm feeling about life in general.

Monday, 11 February 2008

This series of articles will cover the theory behind creating a simple eCommerce system.

Of all the components of an eCommerce site, the shopping cart will be the hardest to develop.

We will store an md5 session key that will link back to databased transactions.

 

  1. When hitting the site, an md5 session key will be created and stored as a session variable.
  2. If the user starts a transaction, a database entry is created in a basket table, and the item is entered into an items table. Both the basket and the item entry use the md5 session key to relate themselves. One basket entry can exist to multiple item entries.
  3. The basket will exist as long as the session is active. 
  4. A cron job will remove non-complete baskets after several hours, keeping these temporary tables relatively clear.
  5. After checkout, the user selects the delivery options, then the order is sent through the google checkout api and the user continues to pay for their items.

 

It's easier than you think to build an eCommerce site, sometimes it's just having that guidance on process to complete it.

Below is some example code you can use to create and store your MD5 key.

session_start();

if($cartID == ''){

if(isset($_SESSION['cartID'])) { 

$cartID = $_SESSION['cartID']; 

echo 'Loaded from session: Cart ID: '.$cartID; 

} elseif(isset($_COOKIE['cartID'])) { 

$cartID = $_COOKIE['cartID']; 

$_SESSION['cartID'] = $cartID; 

echo 'Loaded from cookie: Cart ID: '.$cartID; 

} else { 

$cartID = md5(uniqid(rand(),true));

$_SESSION['cartID'] = $cartID; 

setcookie('cartID', $cartID, time() +432000);

echo 'Created md5 key: '.$cartID;

}

}

 



Tags: eCommerce PHP Shopping Tutorial
Featured Articles
Recent Articles