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.
- 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
- PHP 5.3 or later
- Sessions enabled in your PHP environment
- Clone or download this repository.
- Include the
Cart.phpfile in your project:require_once 'Cart.php';
- Start a PHP session at the beginning of your script if not already started:
session_start();
$cart = new Cart();$item = array(
'id' => 1,
'name' => 'Product Name',
'quantity' => 2,
'price' => 100
// 'options' => array('size' => 'L', 'color' => 'red') // Optional
);
$cart->insert($item);$cart->update(array(
'rowid' => $rowid, // Obtain rowid from cart contents
'quantity' => 3
));$cart->remove($rowid);$items = $cart->contents();$total = $cart->total();$cart->destroy();See index.php for a basic usage example.
This project is licensed under the GPL License. See the LICENSE file for details.
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!