RedCoin
(RedCoin)
金牌会员
 
资深会员
UID 29099
精华
0
积分 1148
帖子 1147
金钱 1148 喜悦币
威望 0
人脉 0
阅读权限 70
注册 2004-6-3 来自 马路边
状态 离线
|
[推荐阅读] 有错吗?
这个是实际应用扩展的购物车类(删除了部分实现代码)
<?php /************************************************************************ * 购物车扩展类,根据实际情况补充必要的代码 ************************************************************************/ class MyCart extends Cart { var $tplNames; //--- 模板名称数组 var $tplStrs; //--- 模板内容数组 var $settings; //--- 购物车设置数组
function MyCart() {}
//--- 初始化必要的参数和设置 function Init() { $this->tplNames = array('Header' => 'TPL_CARTHEADER', 'Body' => 'TPL_CARTBODY', 'Footer' => 'TPL_CARTFOOTER' ); $this->tplNames = array('Header' => '', 'Body' => '', 'Footer' => '' ); $this->settings = array(); }
//--- 保存购物车信息到session, // 保存购物车简要信息到cookie(品种数cart_ctn,总件数cart_pcs,总额cart_sum) function UpdateCart() { if(isset($this->items)) { $_SESSION['items'] = $this->items;
setcookie('cart_cnt', count($this->items)); $pcs = 0; $sum = 0; foreach($this->items as $goods) { $pcs += $goods['qty']; $sum += $goods['qty'] * $goods['price']; } setcookie('cart_pcs', $pcs); setcookie('cart_sum', sprintf('%1.2f', $sum)); } else { unset($_SESSION['items']);
setcookie('cart_cnt', '0'); setcookie('cart_pcs', '0'); setcookie('cart_sum', '0.00'); } }
//--- 显示购物车明细,返回生成的HTML文本 function ShowCart() { $output = ''; /* ... */
return $output; }
//--- 载入模板 function LoadTpl() { return true; }
//--- 输出页面 function Execute() { if(LoadTpl()) echo ShowCart(); } } ?>
|
|