PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of Ahmed Rehan   PHP Shopping Cart Library   ???   Download  
File: ???
Role: Auxiliary data
Content type: text/markdown
Description: Auxiliary data
Class: PHP Shopping Cart Library
Manage a shopping cart stored in session variables
Author: By
Last change: Update README.md
Date: 10 days ago
Size: 1,914 bytes
 

Contents

Class file image Download

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!