<?
/* ***************************************
名称: cart.php
作者: psdshow
联系方式: psdshow@yahoo.com.cn
版本号: 1.0
版权:
编写日期: 2005年12月11日
文件描述: 用于购物车的实现,只用了一个SESSION,可以通过$Attribe扩展
修改日志:
**************************************** */
class Cart{
var $Item = array ();
// 初始化
function Cart( $SessionName ){
$this -> Item = & $_SESSION [ $SessionName ];
}
// 增加一个商品
function AddItem( $ID , $Name , $Count , $Price , $Image , $Description , $Attribe ){
if ( ! isset ( $this -> Item[ $ID ])){
$this -> Item[ $ID ] = array ( ' Name ' => $Name ,
' Count ' => intval ( $Count ) ,
' Price ' => $Price ,
' Image ' => $Image ,
' Description ' => $Description ,
' Attribe ' => $Attribe
);
}
else {
$TMPCount = $this -> Item[ $ID ][ ' Count ' ] + intval ( $Count );
$this -> Item[ $ID ] = array ( ' Name ' => $Name ,
' Count ' => $TMPCount ,
' Price ' => $Price ,
' Image ' => $Image ,
' Description ' => $Description ,
' Attribe ' => $Attribe
);
}
}
// 删除一个商品
function DeleteItem( $ID ){
unset ( $this -> Item[ $ID ]);
}
// 修改一个商品
function ModifyItem( $ID , $Count ){
$this -> Item[ $ID ][ ' Count ' ] = intval ( $Count );
}
function ModifyAttribe( $ID , $Attribe ){
$this -> Item[ $ID ][ ' Attribe ' ] = $Attribe ;
}
// 取得总价值
function GetTotalCost(){
if ( is_array ( $this -> Item)){
foreach ( $this -> Item as $K => $V ){
$Total += $this -> Item[ $K ][ ' Count ' ] * $this -> Item[ $K ][ ' Price ' ];
}
}
return $Total ;
}
// 返回全部商品
function GetAllItem(){
return $this -> Item;
}
// 清空购物篮
function ClearItem(){
$this -> Item = '' ;
}
}
?>
/* ***************************************
名称: cart.php
作者: psdshow
联系方式: psdshow@yahoo.com.cn
版本号: 1.0
版权:
编写日期: 2005年12月11日
文件描述: 用于购物车的实现,只用了一个SESSION,可以通过$Attribe扩展
修改日志:
**************************************** */
class Cart{
var $Item = array ();
// 初始化
function Cart( $SessionName ){
$this -> Item = & $_SESSION [ $SessionName ];
}
// 增加一个商品
function AddItem( $ID , $Name , $Count , $Price , $Image , $Description , $Attribe ){
if ( ! isset ( $this -> Item[ $ID ])){
$this -> Item[ $ID ] = array ( ' Name ' => $Name ,
' Count ' => intval ( $Count ) ,
' Price ' => $Price ,
' Image ' => $Image ,
' Description ' => $Description ,
' Attribe ' => $Attribe
);
}
else {
$TMPCount = $this -> Item[ $ID ][ ' Count ' ] + intval ( $Count );
$this -> Item[ $ID ] = array ( ' Name ' => $Name ,
' Count ' => $TMPCount ,
' Price ' => $Price ,
' Image ' => $Image ,
' Description ' => $Description ,
' Attribe ' => $Attribe
);
}
}
// 删除一个商品
function DeleteItem( $ID ){
unset ( $this -> Item[ $ID ]);
}
// 修改一个商品
function ModifyItem( $ID , $Count ){
$this -> Item[ $ID ][ ' Count ' ] = intval ( $Count );
}
function ModifyAttribe( $ID , $Attribe ){
$this -> Item[ $ID ][ ' Attribe ' ] = $Attribe ;
}
// 取得总价值
function GetTotalCost(){
if ( is_array ( $this -> Item)){
foreach ( $this -> Item as $K => $V ){
$Total += $this -> Item[ $K ][ ' Count ' ] * $this -> Item[ $K ][ ' Price ' ];
}
}
return $Total ;
}
// 返回全部商品
function GetAllItem(){
return $this -> Item;
}
// 清空购物篮
function ClearItem(){
$this -> Item = '' ;
}
}
?>