session_name("svarog_shop"); session_start(); session_register("order"); session_register("total_price"); arr2global($_SESSION); if(!isset($order)) $total_price=0; //add to cart if(isset($addtocart)) { if($quantity=="") $quantity=1; if(!isset($order["$buy_id"])) { $order["$buy_id"]=array("id"=>"$buy_id","name"=>"$name","price"=>"$price","quantity"=>"$quantity","total"=>$price*$quantity); $total_price+=$price*$quantity; } else { $total_price-=$order["$buy_id"]["price"]*$order["$buy_id"]["quantity"]; $order["$buy_id"]["quantity"]=$quantity; $order["$buy_id"]["total"]=$price*$quantity; $total_price+=$price*$quantity; if($quantity==0) unset($order["$buy_id"]); } } //empty cart if(isset($emptycart)) { $total_price=0; foreach($order as $key=>$value) { unset($order[$key]); } } //update cart if(isset($update)) { if(isset($quan)) { foreach($quan as $key=>$value) { $total_price-=$order[$key]["price"]*$order[$key]["quantity"]; $order[$key]["quantity"]=$quan[$key]; $order[$key]["total"]=$order[$key]["price"]*$quan[$key]; $total_price+=$order[$key]["total"]; if($quan[$key]==0) { unset($order[$key]); unset($del[$key]); } } } if(isset($del)) { foreach($del as $key=>$value) { if($del[$key]==1) { $total_price-=$order[$key]["total"]; unset($order[$key]); } } } } $_SESSION["order"]=$order; $_SESSION["total_price"]=$total_price; ?>
|