Search

Wednesday, 27 January 2010

Simple shopping cart class using php

Hello,

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:
http://nasaralla.googlecode.com/files/shopping_cart.php

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

___________________________________________________
//include the file
include("shopping_cart.php");
//start a session
session_start();
//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
$cart->add_to_cart($itm1);
$cart->add_to_cart($itm2);
$cart->add_to_cart($itm3);
$cart->add_to_cart($itm4);
$cart->add_to_cart($itm5);

//print xml based status of the cart
$cart->print_cart_status();

//remove item in 3rd position (4th item)
$cart->remove_element(3);

//print xml based status of the cart
$cart->print_cart_status();
//end session
session_destroy();
___________________________________________________

And the xml output is like the following:
___________________________________________________


___________________________________________________

5 comments:

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

    ReplyDelete
  2. nice post.
    http://www.izzonet.com/

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete

There was an error in this gadget