Easy PHP Cart

Released 7 years ago , Last update 7 years ago

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

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();
2.5
  • 5 0
  • 4 0
  • 3 1
  • 2 1
  • 1 0
2 Reviews Read Reviews

Pricing

14 day 14-day money-back guarantee

FREE

GNU GPL

The GNU GPL is an open-source license.

License » GNU GPL Download

Get A Quote

What do you need?
  • Custom development
  • Integration
  • Customization / Reskinning
  • Consultation
When do you need it?
  • Soon
  • Next week
  • Next month
  • Anytime

Thanks for getting in touch!

Your quote details have been received and we'll get back to you soon.


Or enter your name and Email
  • P Peter 3 years ago
    very useful script. But can you please still add an Total price method ?
  • A asdasd 3 years ago
    deleted
  • A azrul 3 years ago
    Nice script... can you explain each parameter? Dsicount (35) mean quantity or id or price? $cart->discount = 35; also bonusProduct = 11... 11 mean id or quantity? $cart->bonusProduct = 11;