CodeIgniter Shopping Cart Library

CodeIgniter is a great PHP framework to work with. One of the items several CodeIgniter Logodevelopers have been asking to be included in the next CodeIgniter release, is a core library for a shopping cart. The library is being added for CI version 1.7.2, and is currently available via SVN on the CodeIgniter website.

UPDATE 09/12/2009: The shopping cart library has now been released as part of the Code Igniter stable release version 1.7.2. You can dowload it at

I have used wfCart class in another CI project I worked on. It provides simple functionality: add, edit, delete products along with displaying the shopping cart contents. wfCart took a little hacking of the code and adding the CI object to the code in order to use some the builtin features of CI. It worked well, but lacked the naming conventions that make CI so great.

I decided to give the Cart library a try, so I put together some simple code to see the functionality of the Cart class. Posted below is download of files you can drop into your CodeIgniter application, and try it out for yourself.

I created a new controller and named it Cart.php.

The code in the controller offers simple functionality:

  • View products
  • View shopping cart
  • Update shopping cart quantities
  • Delete products from shopping cart

You will need a table to your database to store the product information.

`product_id` int(10) NOT NULL AUTO_INCREMENT,
`product_sku` varchar(100) NOT NULL,
`product_description` varchar(200) NOT NULL,
`product_family` varchar(250) NOT NULL,
`product_quantity` double(10,4) NOT NULL,
`product_price` double(10,2) NOT NULL,
`vendor_id` int(10) NOT NULL,
`user_id` int(10) NOT NULL,
PRIMARY KEY (`product_id`),
UNIQUE KEY `product_id` (`product_id`)

Just add a couple products to the table, and you should be able to test this out.

Download Demo