PHP Classes

PHP Shopping Cart Library: Manage a shopping cart stored in session variables

Recommend this page to a friend!
     
  Info   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2025-06-04 (3 hours ago) RSS 2.0 feedNot enough user ratingsTotal: 427 All time: 6,344 This week: 33Up
Version License PHP version Categories
cart 1.1Artistic License5.5PHP 5, E-Commerce
Description 

Author

This class can manage a shopping cart stored in session variables.

It can perform several types of operations to manipulate the contents of a shopping cart.

Currently it can insert new items, update cart items, save the cart items to a session variable, remove items, destroy the whole shopping cart, and retrieve the list of items.

Picture of Ahmed Rehan
Name: Ahmed Rehan <contact>
Classes: 1 package by
Country: Pakistan Pakistan
Age: 30
All time rank: 346043 in Pakistan Pakistan
Week rank: 195 Up3 in Pakistan Pakistan Up

Recommendations

Point of Sale software
I need a good package of point of sale software

Details

ShoppingCartLibraryv1.0

A simple, extensible PHP class for integrating a shopping cart into your web applications. This library was developed at the University Institute of Information Technology (UIIT-UAAR) and is released under the GPL license.

Features

  • Add items to cart
  • Delete items from cart
  • Update items in cart
  • Save cart in session
  • Display all items in cart (in reverse order)
  • Destroy the cart (usually after placing an order)
  • Calculate total amount and total items

Getting Started

Requirements

  • PHP 5.3 or later
  • Sessions enabled in your PHP environment

Installation

  1. Clone or download this repository.
  2. Include the `Cart.php` file in your project:
    require_once 'Cart.php';
    
  3. Start a PHP session at the beginning of your script if not already started:
    session_start();
    

Usage

Initialize the Cart

$cart = new Cart();

Add an Item

$item = array(
    'id' => 1,
    'name' => 'Product Name',
    'quantity' => 2,
    'price' => 100
    // 'options' => array('size' => 'L', 'color' => 'red') // Optional
);
$cart->insert($item);

Update an Item

$cart->update(array(
    'rowid' => $rowid, // Obtain rowid from cart contents
    'quantity' => 3
));

Remove an Item

$cart->remove($rowid);

Get Cart Contents

$items = $cart->contents();

Get Cart Total

$total = $cart->total();

Destroy the Cart

$cart->destroy();

Example

See index.php for a basic usage example.

License

This project is licensed under the GPL License. See the LICENSE file for details.

Author

Ahmed Rehan University Institute of Information Technology (UIIT-UAAR)

This library is intended for educational purposes and basic PHP shopping cart integration. Contributions and improvements are welcome!


  Files folder image Files (4)  
File Role Description
Plain text file Cart.php Class Class source
Accessible without login Plain text file index.php Data Auxiliary script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Data Auxiliary data

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:427
This week:0
All time:6,344
This week:33Up