cart.php

<?
  
/* ***************************************
  名称:  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 = '' ;
        }
}
?>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值