class cart
{
function r_type_count() //返回有多少种产品
{
return isset($_SESSION["cart"])?count($_SESSION["cart"]):0;
}
function r_totting($type="total") //返回产品合计 $type 就是键名
{
$temp=0;
for($i=0;$this->r_type_count()>$i;$i++)
{
$temp+=$_SESSION["cart"][$i][$type];
}
return $temp;
} function add($cid,$count,$price,$cname,$discount=10) //添加产品
{
for($i=0;$this->r_type_count()>$i;$i++) //如果产品中有 则在数量上+1 没有则添加
{
if($_SESSION["cart"][$i]["cid"]==$cid)
{
$_SESSION["cart"][$i]["count"]+=$count;
$_SESSION["cart"][$i]["total"]=$_SESSION["cart"][$i]["price"]*$_SESSION["cart"][$i]["count"];
$_SESSION["cart"][$i]["d_total"]=$_SESSION["cart"][$i]["d_price"]*$_SESSION["cart"][$i]["count"];
return ;
}
}
$j=$this->r_type_count();
$total=round($price*$count,2);
$d_price=round($price*($discount*0.1),2);
$d_total=round($d_price*$count,2);
$_SESSION["cart"][$j]["cid"]=$cid;
$_SESSION["cart"][$j]["count"]=$count;
$_SESSION["cart"][$j]["price"]=$price;
$_SESSION["cart"][$j]["d_price"]=$d_price;
$_SESSION["cart"][$j]["cname"]=$cname;
$_SESSION["cart"][$j]["discount"]=$discount;
$_SESSION["cart"][$j]["total"]=$total;
$_SESSION["cart"][$j]["d_total"]=$d_total;
}
function del($cid,$type="all") //删除产品 all 表示 删除这一种 one 表示删除 这一种中的一个
{
for($i=0;$this->r_type_count()>$i;$i++)
{
if($_SESSION["cart"][$i]["cid"]==$cid)
{
if($type=="all")
{
array_splice($_SESSION["cart"],$i,1);
}
else if($type=="one")
{
if($_SESSION["cart"][$i]["count"]>1)
{
$_SESSION["cart"][$i]["count"]-=1;
$_SESSION["cart"][$i]["total"]-=$_SESSION["cart"][$i]["price"];
$_SESSION["cart"][$i]["d_total"]-=$_SESSION["cart"][$i]["d_price"];
}
else
{
array_splice($_SESSION["cart"],$i,1);
}
}
return;
}
}
}
}
$_SESSION["cart"][$j]["cid"]=$cid; // 产品ID $_SESSION["cart"][$j]["count"]=$count;// 数量 $_SESSION["cart"][$j]["price"]=$price;// 单价 $_SESSION["cart"][$j]["d_price"]=$d_price;// 折扣价 $_SESSION["cart"][$j]["cname"]=$cname;// 产品名称 $_SESSION["cart"][$j]["discount"]=$discount;// 折扣 $_SESSION["cart"][$j]["total"]=$total;// 总价 (不折扣) $_SESSION["cart"][$j]["d_total"]=$d_total;// 总价 (折扣)
1.订单号准备 返回初次付款的时候 写入数据库时 在生成2.这个类还没有写完 也没有测试有些逻辑错误 指出来就行了 不过不同太 在意 主要帮我看看 这个思路3.谢谢
商品还在你的购物车中...
像 osc ,zen cart opencart magento 都是....