Home
The GNU GPL is an
open-source license.
A simple shopping cart for beginners - a simple add/remover product Read full license
Copyright Irimia Octavian, all rights reserved.
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).
// 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();
Good concept idea, but realisation needs an additional work to use it real life project- Dailis Tukāns, 9 months ago
Copyright Irimia Octavian, all rights reserved.
Questions & Comments
Leave a comment
Log-in now or register for a free account.