------- an extract of the Cart.inc file --------
<?php
switch ($HTTP_GET_VARS['cart_action']) {
case "Add":
$cart->AddItem($HTTP_GET_VARS['pid']);
$HTTP_SESSION_VARS['DEBUG_INCREMENTER'] ++; // This one increase the value
break;
// store the cart in the session
$HTTP_SESSION_VARS['cart'] = $cart;
?>
--------the Shopping Cart Class extract -------------
<?php
Class ShoppingCart {
var $items = array();
// AddItem recieved the product_number of an item and adds it to the cart.
// If the product_number is already in the cart quantity is increased by 1
Function AddItem ($item) {
$HTTP_SESSION_VARS['DEBUG_INCREMENTER'] ++; // This one doesn't
if ($this->items[$item]) {
$this->items[$item] = $this->items[$item] + 1;
} else {
$this->items[$item] = 1;
}
}
?>
---------------The Index Page Calling the Class----------------
<?php // This is the Index Page that uses the HTML TEMPLATE 2 Class
require_once("Classes/HTML.class.php"); // include the class
require_once("Classes/ShoppingCart.class.php"); // include the class
session_start();
// Establish shopping cart
If (isset($HTTP_SESSION_VARS['cart'])) {
$cart = $HTTP_SESSION_VARS['cart'];
} else {
$cart = new ShoppingCart();
$HTTP_SESSION_VARS['cart'] = 0; // register the session variable
}
$HTTP_SESSION_VARS['cart'] = $cart; // store the cart in the session
IF ($HTTP_GET_VARS['cart_action']) {
// If a request is made to act on the shopping cart then process the request
require_once('cart.inc.php');
}
$page->CreatePage();
unset($page);
?>