PHP Classes

PHP E-commerce Cart Class: Manipulate items in a shopping cart

Recommend this page to a friend!
  Info   View files Example   View files View files (7)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 652 All time: 4,924 This week: 206Up
Version License PHP version Categories
ecommerce-class 0.8GNU General Publi...5.4PHP 5, E-Commerce


This class can manipulate items in a shopping cart.

It extends the ArrayObject class to manipulate a collection of items in a shopping cart performing operations like adding, getting, updating and removing items, search items, and compute the cart total price.

A separate product class can be used to define details the items to be added to the cart like price, quantity, description and taxes.

Picture of Nicholas Oliveira
  Performance   Level  
Name: Nicholas Oliveira <contact>
Classes: 4 packages by
Country: Brazil Brazil
Age: 38
All time rank: 70252 in Brazil Brazil
Week rank: 271 Up21 in Brazil Brazil Up



include "../Product.class.php";

Produto extends Product {

    public function
$this->price - $this->vat;




    if( isset(
//print "AHU";
header("location: test.php");

    if( isset(

header("location: test.php");


//comment this code after SESSION IS WROTE


//foreach ($cart as $key => $value) {
// var_dump($key, $value);



if(!isset($_SESSION['cart']) || empty($_SESSION['cart']) ){
'Write The Session in <a href="write_session.php">Write Session </a>Before Run';

<!doctype html>
<html lang="en">
    <meta charset="UTF-8">

<form method="POST">
    <p>This Lists is been indexed by the array Index. but you can change to get only ID from your best flavoured DB</p>
    <a href="write_session.php?force=true">Force Session Write</a>

= $_SESSION['cart']->getIterator();

"No Products";

            }else {

$it->valid()){ ?>
                        <td><?php echo $it->current()->id; ?></td>
                        <td><?php echo $it->current()->name; ?></td>
                        <td><?php echo $it->current()->description; ?></td>
                        <td><?php echo Utils::Moneyformat($it->current()->price); ?></td>
                        <td><?php echo $it->current()->quantity; ?></td>
                        <td><a href="<?php print "?remover=".$it->key(); ?>">Remove Product</a> </td>



            <td>Total: <?php print sprintf("%01.2f",$_SESSION['cart']->getTotal()); ?></td>
    <a href="?limpar_cart=true">Empty Cart</a>

= $_SESSION['cart']->search_by_index(1);

$id = $_SESSION['cart']->getId($d);
var_dump($id)." ^ Show Index will occur error when you delete this ID";



ec-cart ======= Simple E-commerce Cart Class You Can create a cart for your e-commerce easily suing this class its intended to use with sessions can support DB if you add funcionalities. before append the class to the cart you should write the product ID from database then you have a class with db working cause makes the intercation with DB not directly

  Files folder image Files  
File Role Description
Files folder imagetest (2 files)
Plain text file Cart.class.php Class Main Cart Class
Plain text file Product.class.php Class Asbtract Class for your product
Accessible without login Plain text file Data Auxiliary data
Accessible without login Plain text file test.bat Data Auxiliary data
Plain text file Utils.class.php Class Just assets of functions not important neither required to run

  Files folder image Files  /  test  
File Role Description
  Accessible without login Plain text file test.php Example Example script
  Accessible without login Plain text file write_session.php Example Example script

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:4,924
This week:206Up