Wednesday, 27 January 2010

Simple shopping cart class using php


My cart class manages the shopping cart facility which almost every e-commerce site requires these days. This class does not do checkout with paypal, google check out or with any such similar services. But you can very easily manage the items being put into and taken away from the cart.

you can download the file from here:

And like in the following example can start managing your items:

//include the file
//start a session
//initialize session variables
$_SESSION["item_list"] = array();
$_SESSION["item_total"] = 0;
//creating some items
$itm1 = new item("1","T-shirt","clothing","fcuk", "10.00", "cotton t-shirt", "image_url_not_available");
$itm2 = new item("2","Trouser","clothing","fcuk", "15.00", "Khaki trouser", "image_url_not_available");
$itm3 = new item("3","Cap","clothing","Next", "5.00", "all size cap", "image_url_not_available");
$itm4 = new item("4","jacket","formal","Austin reed", "100.00", "bond casino royal style", "image_url_not_available");
$itm5 = new item("5","Shoes","formal","Aldo", "50.00", "black naughty boy", "image_url_not_available");

//create your cart
$cart = new shopping_cart();

//add items to your cart

//print xml based status of the cart

//remove item in 3rd position (4th item)

//print xml based status of the cart
//end session

And the xml output is like the following:



  1. Thanks for sharing these. I’m looking for simple shopping cart php when I found your blog. I will try this one.

  2. nice post.

  3. Just desire to say your article is as astounding. The clarity in your post is simply nice and i could assume you are an expert on this subject. Fine with your permission let me to grab your feed to keep updated with forthcoming post. Thanks a million and please keep up the gratifying work.
    PHP Shopping Cart

  4. Your really good information. I cant believe I just did not know how much this. Thank you with detailed information on this topic for me. I really appreciate it, really was impressed.

    eCommerce platform