= '0' && `products_status` = '0'")); if($num == 1){ if(isset($_SESSION["cart"]["$_POST[pid]"])){ if(!empty($_POST["qty"])) $_SESSION["cart"]["$_POST[pid]"] = $_POST["qty"]; else $_SESSION["cart"]["$_POST[pid]"]++; }else{ if(!empty($_POST["qty"])) $_SESSION["cart"]["$_POST[pid]"] = $_POST["qty"]; else $_SESSION["cart"]["$_POST[pid]"] = 1; } } $_SESSION["total_items"] = cart_calculate_items($_SESSION["cart"]); $_SESSION["total_price"] = cart_calculate_price($_SESSION["cart"]); $s_cart = serialize($_SESSION["cart"]); @header("Location: $script_url?action=view"); exit; } //====================================================================================== // ยกเลิก ออเดอร์ //====================================================================================== if(@$_GET["action"] == "cancel"){ //session_unregister("cart"); //session_unregister("total_items"); //session_unregister("total_price"); //session_unregister("d_name"); //session_unregister("d_price"); //session_unregister("skey"); @header("Location: $script_url?action=view"); exit; } //====================================================================================== // ลบรายการสินค้า //====================================================================================== if(@$_GET["action"] == "delete" && !empty($_GET["pid"])){ unset($_SESSION["cart"]["$_GET[pid]"]); $_SESSION["total_items"] = cart_calculate_items($_SESSION["cart"]); $_SESSION["total_price"] = cart_calculate_price($_SESSION["cart"]); $s_cart = serialize($_SESSION["cart"]); @header("Location: $script_url?action=view"); exit; } //====================================================================================== // ปรับปรุงรายการสินค้า //====================================================================================== if(@$_POST["action"] == "Update"){ foreach($_POST as $key => $value){ if(!eregi("^action|^submit|^id", $key)){ $id = eregi_replace("pd", "", $key); if($_SESSION["cart"]["$id"]){ $_SESSION["cart"]["$id"] = $value; } } } $_SESSION["total_items"] = cart_calculate_items($_SESSION["cart"]); $_SESSION["total_price"] = cart_calculate_price($_SESSION["cart"]); $s_cart = serialize($_SESSION["cart"]); @header("Location: $script_url?action=view"); exit; } //====================================================================================== // คำนวนจำนวนสินค้าที่สั่งซื้อทั้งหมด //====================================================================================== function cart_calculate_items($cart){ $items = 0; if(is_array($cart)){ foreach($_SESSION["cart"] as $key => $value){ $items += $value; } } return $items; } //====================================================================================== // คำนวนยอดเงินรวมทั้งสิน //====================================================================================== function cart_calculate_price($cart){ $price = 0.00; if(is_array($cart)){ foreach($cart as $key => $value){ if($row = mysql_fetch_array(mysql_query("Select `products_price` From `products` Where `products_id` = '$key'"))){ $item_price = $row["products_price"]; $price += $item_price * $value; } } } return $price; } //====================================================================================== // สำหรับแสดงรายการสินค้า //====================================================================================== if(@$_REQUEST["action"] == "view"){ include "template_cart_top1.php"; } ?>