Just archiving this project from my Open Source Software class.
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
// Start session management with a persistent cookie
|
||||
$lifetime = 60 * 60 * 24 * 14; // 2 weeks in seconds
|
||||
// $lifetime = 0; // per-session cookie
|
||||
session_set_cookie_params($lifetime, '/');
|
||||
session_start();
|
||||
|
||||
// Create a cart array if needed
|
||||
if (empty($_SESSION['cart12'])) $_SESSION['cart12'] = array();
|
||||
|
||||
// Create a table of products
|
||||
$products = array();
|
||||
$products['D2400'] = array('name' => 'Dimension 2400', 'cost' => '149.50');
|
||||
$products['AG3'] = array('name' => 'Macintosh G3', 'cost' => '199.50');
|
||||
$products['DE510'] = array('name' => 'Dimension E510', 'cost' => '299.50');
|
||||
|
||||
// Include cart functions
|
||||
require_once('config/cart.php');
|
||||
|
||||
// Get the action to perform
|
||||
if (isset($_POST['action'])) {
|
||||
$action = $_POST['action'];
|
||||
} else if (isset($_GET['action'])) {
|
||||
$action = $_GET['action'];
|
||||
} else {
|
||||
$action = 'show_add_item';
|
||||
}
|
||||
|
||||
// Add or update cart as needed
|
||||
switch($action) {
|
||||
case 'add':
|
||||
add_item($_POST['productkey'], $_POST['itemqty']);
|
||||
include("cart-view.php");
|
||||
break;
|
||||
case 'update':
|
||||
$new_qty_list = $_POST['newqty'];
|
||||
foreach($new_qty_list as $key => $qty) {
|
||||
if ($_SESSION['cart12'][$key]['qty'] != $qty) {
|
||||
update_item($key, $qty);
|
||||
}
|
||||
}
|
||||
include('cart-view.php');
|
||||
break;
|
||||
case 'show_cart':
|
||||
include('cart-view.php');
|
||||
break;
|
||||
case 'show_add_item':
|
||||
include('store.php');
|
||||
break;
|
||||
case 'empty_cart':
|
||||
unset($_SESSION['cart12']);
|
||||
include('cart-view.php');
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user