Login   Register  
PHP Classes
elePHPant
Icontem

File: Cart.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of RAZA  >  shopcart  >  Cart.php  >  Download  
File: Cart.php
Role: Example script
Content type: text/plain
Description: Shopping Cart Page
Class: shopcart
Manage a shopping cart stored in a MySQL database
Author: By
Last change:
Date: 2009-08-10 02:47
Size: 2,185 bytes
 

Contents

Class file image Download
<?php
require('includes/application.php');

if(isset(
$_GET['add'])) {
    
$pCode=mysql_real_escape_string($_GET['add']);
    
$pInfo=$site->GetProductInfo($pCode);

    if(!isset(
$_SESSION['cart_active']))
        
$_SESSION['cart_active']=true;
                
    
$cart->Add_Cart_Item($pCode,1);    
    
header("location: cart.php");
}elseif(isset(
$_GET['remove'])) {
    
$pCode=mysql_real_escape_string($_GET['remove']);
    
    
$cart->Delete_Cart_Item($pCode);
    
if(
sizeof($cart->Get_Cart_Contents())==0)
    unset(
$_SESSION['cart_active']);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sample PHP Paypal Shopping Cart - Shopping Cart</title>
<link rel="stylesheet" type="text/css" href="css/site.css" />
</head>

<body>
<?php
echo '<h2>Items in cart</h2>';
echo 
'<a href="index.php">Goto Products</a>';
echo 
'<p>&nbsp;</p>';
if(
$cart->itemcount 0) {
    echo 
'<table>';
    echo    
'<thead>';    
    echo        
'<tr>';
    echo            
'<th>Name</th>';
    echo            
'<th>Quantity</th>';    
    echo            
'<th>Price</th>';
    echo            
'<th>Sub Total</th>';        
    echo        
'</tr>';
    echo    
'</thead>';
    echo    
'<tbody>';
    foreach(
$cart->Get_Cart_Contents() as $item) {
    echo        
'<tr>';
    echo            
'<td>'.$item['info'].'&nbsp;&nbsp;<a href="Cart.php?remove='.$item['id'].'">Remove</a></td>';
    echo            
'<td>'.$item['qty'].'</td>';
    echo            
'<td>'.number_format($item['price'],2).'</td>';    
    echo            
'<td>'.number_format($item['subtotal'],2).'</td>';        
    echo        
'</tr>';
    }
    echo    
'</tbody>';
    echo    
'<tfoot>';
    echo        
'<tr>';
    echo            
'<th>&nbsp;</th>';
    echo            
'<th>&nbsp;</th>';    
    echo            
'<th>Total: USD&nbsp;</th>';
    echo            
'<th>'.number_format($cart->total,2).'</th>';    
    echo        
'</tr>';
    echo        
'<tr>';
    echo            
'<th><a href="Checkout.php"><input type="button" name="btnPay" value="Click to Pay with Paypal" /></a></th>';
    echo            
'<th>&nbsp;</th>';    
    echo            
'<th>&nbsp;</th>';
    echo            
'<th>&nbsp;</th>';    
    echo        
'</tr>';    
    echo    
'</tfoot>';
    echo 
'</table>';
} else {
    echo 
"No items in cart";
}
?>
</body>
</html>