コード例 #1
0
    */
    public function all()
    {
        return $this->items;
    }
    /*
    清空购物车
    */
    public function clear()
    {
        $this->items = array();
    }
}
//print_r(CartTool::getCart());
/* 测试*/
$cart = CartTool::getCart();
if (!isset($_GET['test'])) {
    $_GET['test'] = '';
}
if ($_GET['test'] == 'addpm') {
    $cart->addItem(1, '手机', '1999', 1);
    echo "购买手机成功";
} elseif ($_GET['test'] == 'addfushi') {
    $cart->addItem(2, '阿迪达斯', '169', 1);
    echo '购买阿迪达斯成功';
} elseif ($_GET['test'] == 'clear') {
    $cart->clear();
    echo "购物车已清空";
} elseif ($_GET['test'] == 'show') {
    print_r($cart->all());
    echo "<br />";
コード例 #2
0
ファイル: flow.php プロジェクト: xiaoxiaoJun/phpper
<?php
/*
@Dscribe:购物流程页面商城的核心功能
@Author:GongBiao
@Date:2015/07/05
*/
header('Content-Type:text/html; charset=utf-8');
define('ACC', true);
require('./include/init.php');

//设置一个动作参数,判断用户想干什么,比如是下订单/写地址/提交/清空购物车等
$act = isset($_GET['act']) ? $_GET['act'] : 'buy';

$cart = CartTool::getCart(); //获取购物车实例
$goods = new GoodsModel();

if($act == 'buy'){ //把商品放入购物车
	$goods_id = isset($_GET['goods_id']) ? $_GET['goods_id'] + 0 : 0;
	$num = isset($_GET['num']) ? $_GET['num'] + 0 : 1;


	if($goods_id){ //$goods_id为真,是想把商品入到购物车里
		$g = $goods->find($goods_id);
		if(!empty($g)){ //说明有商品

			//需要判断此商品,是否在回收站
			//此商品是否下架
			if($g['is_delete'] == 1 || $g['is_on_sale'] == 0){
				$msg = '此商品不能购买';
				include(ROOT . 'view/front/msg.html');
				exit;