GNU GPL FREE

The GNU GPL is an
open-source license.
A simple shopping cart for beginners - a simple add/remover product Read full license

You need to log-in or create an account
  • Create an account
  • Log-in
  • Please use your real name.
  • Account activation link will be sent to this address.
  • Minimum 8 characters

Clicking this button confirms you read and agreed to the terms of use and privacy policy.

(2 ratings)

Easy PHP Cart

A simple OOP PHP shopping cart for adding and removing products.

Share and win up to $15k in prizes each month!Learn more

Share

Description

This class allows you to add and remove products from an OOP cart. Cart is managed in the session so it is saved between pages and optionally between visits (depending on session configuration).

Usage example

// Start sessions
session_start();
// Set all errors to ON for development and to 0 (zero) when public
error_reporting(E_ALL);

// require the class
require 'class.cart.inc.php';

// set cart name [session key]
$cartName = 'basicCart';

// instance the cart class
$cart = new cart($cartName);

// Add some products to the cart. 
// Here we add a product with an ID of 23, and a quantity of 8.
$cart->addProduct(23, 8, false);
// Set special discount for this product
$cart->discount = 32;

// The 3rd argument allows you to increase quantity if the product exists
$cart->addProduct(16, 2, true);

// set special discount for this too
$cart->addProduct(53, 5, false);
$cart->discount = 35;
$cart->bonusProduct = 11;

echo 'We have '.$cart->cartCount().' products';
$cart->viewCart();

Questions & Comments

Leave a comment

You must be logged-in to leave a comment.
Log-in now or register for a free account.
No comments have been posted yet.
You must be logged-in to vote. Log-in to your account or register now.
View all 1 reviews »

User Reviews

  • 2 of 2 people found this review helpful
    Good concept idea, but realisation needs an additional work to use it real life project
    - Dailis Tukāns, 9 months ago
    Flag review
    Was this helpful? Yes No