|
|
|
ดูโค้ดตะกร้าสินค้าให้ผมหน่อยคับ ผมไม่สามารถเปลี่ยนจำนวนสั่งซื้อได้เขียนโค้ดอัพเดทไม่เป็นคับและก็สร้างไฟล์ชำระเงินด้วยอะคับ |
|
|
|
|
|
|
|
ผมไม่สามารถเปลี่ยนจำนวนสั่งซื้อได้เขียนโค้ดอัพเดทไม่เป็นคับและก็สร้างไฟล์ชำระเงินด้วยอะคับ ช่วยหน่อยนะคับ งง มากๆ โค้ดยาวไปหน่อยนะคับ
<?php
error_reporting(E_ALL);
session_start();
include("connectionDB.php");
$expire = 3600;
$time=time();
$expire=$time+$expire;
$script_url=$_SERVER["PHP_SELF"];
if(!isset($_SESSION['cart']))
{
if(isset($_COOKIE['cart']))
{
$_SESSION['cart']=array();
$_SESSION['cart']=unserialize(stripslashes($_COOKIE['cart']));
$_SESSION['total_items']=cart_calculate_items($_SESSION['cart']);
$_SESSION['total_price']=cart_calculate_price($_SESSION['cart']);
}
else
{
$_SESSION['cart']=array();
$_SESSION['total_items']=0;
$_SESSION['total_price']=0.00;
$s_cart = serialize($_SESSION['cart']);
setcookie('cart',$s_cart,$expire);
}
}
if($_GET['action']=='add')
{
$item=$_GET['pid'];
if(isset($_SESSION['cart'][$item]))
{
$_SESSION['cart'][$item]++;
}
else
{
$_SESSION['cart'][$item]=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']=="del")
{
$productID=$_GET['pid'];
unset($_SESSION['cart'][$productID]);
$_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']=="view")
{
cart_show($_SESSION['cart'],$pictures='false',$editable='true');
}
//=====================
// ฟังก์ชันคำนวณจำนวนสินค้า
function cart_calculate_items($cart)
{
$items=0;
if(is_array($cart))
{
foreach($_SESSION['cart']as $productID =>$qty)
{
$items+=$qty;
}
}
return $items;
}
//======================
// ฟังก์ชันคำนวณราคา
function cart_calculate_price($cart)
{
$price=0.00;
if(is_array($cart))
{
foreach($cart as $productID => $qty)
{
$query ="select price from product where pro_id ='$productID'";
$result = mysql_query($query);
if($result)
{
$row_result=mysql_fetch_assoc($result);
$item_price=$row_result['price'];
$price+=$item_price*$qty;
}
}
}
return $price;
}
//====================================
function db_to_array($result)
{
$result_array=array();
for($count=1;$row=@mysql_fetch_array($result);$count++)
$result_array[$count]=$row;
return $result_array;
}
//====================================
function cart_get_item_details($productID)
{
$query="select * from product where pro_id='$productID'";
mysql_query("SET character_set_results =tis620");
mysql_query("SET character_set_client =tis620");
mysql_query("SET character_set_connection =tis620");
$result = mysql_query($query);
$row_result = mysql_fetch_assoc($result);
return $row_result;
}
//===================================
function cart_show($cart,$pictures='false',$editable='true')
{
include("cart_top.php");
$i=1;
foreach($cart as $productID=>$qty)
{
$product = cart_get_item_details($productID);
$bgcolor=($i++%2)?'#F@FAEB':'#E6F2DF';
echo"<form>\n";
echo"<tr bgcolor=\"$bgcolor\">\n";
echo"<td align=\"center\">";
echo"<a href=\"basket.php?action=del&pid=".$product['pro_id']."\">";
echo"ลบ";
echo"</a>";
echo"</td>\n";
echo"<td>".$product['proname']."</td>\n";
echo"<td valign=top align=center>";
echo"<input type=\"text\" name=\"pro_id\" value=$qty size=2>";
echo"</td>\n";
echo"<td valign=top align=right>".number_format($product['price'],
2,'.',',')."</td>\n";
echo"<td valign=top align=right>".number_format(($qty*$product['price']),2,'.',',')."</td>\n";
echo"</tr>\n";
echo"</form>\n";
}
echo"<tr>\n";
echo"<td colspan=5><hr size=1></td>\n";
echo"</tr>\n";
echo"<tr>\n";
echo"<td colspan=3 align=\"center\"valign=middle>
</td>\n";
echo"<td align=left><b>ยอดรวม</b></td>\n";
echo"<td align=right>".number_format($_SESSION['total_price'],2,'.',',')."</td>\n";
echo"</tr>\n";
echo"<tr>\n";
echo"<td colspan=3rowspan=4> </td>\n";
echo"<td align=left><b>ค่าจัดส่ง</b></td>\n";
echo"<td align=right>";
if($_SESSION['total_price']==0)
{
$pay_delivery=0;
}
else
{
if($_SESSION['total_price']>=1500)
$pay_delivery=0;
else
$pay_delivery=150;
}
echo number_format($pay_delivery,2,'.',',');
echo"</td>\n";
echo"</tr>\n";
echo"<tr>\n";
echo"<td align=left><b>ภาษี 7%</b></td>\n";
echo"<td align=right bgcolor=\"#FFFF99\">";
$tax=$_SESSION['total_price']*0.07;
echo number_format($tax,2,'.',',');
echo"</td>\n";
echo"</tr>\n";
echo"<tr>\n";
echo"<td colspan=3><hr size=1></td>\n";
echo"</tr>\n";
echo"<tr>\n";
echo"<td align=left><b>รวมทั้งสิ้น</b></td>\n";
echo"<td align=right bgcolor=\"#99FF99\">";
$paymoney =($_SESSION['total_price']+$pay_delivery+$tax);
echo number_format($paymoney,2,'.',',');
echo"</td>\n";
echo"</tr>\n";
echo"<tr>\n";
echo"<td colspan=5><br>\n";
echo"หากท่านไม่ได้รับสินค้าภายใน 3 วัน โปรดติดต่อกลับ 085-127-5611</td>\n";
echo"</tr>\n";
echo"</table>\n";
echo"<div align=center>\n";
echo"<p align=center>\n";
echo"<a href=\"product.php\">ซื้อสินค้าต่อ</a>\n";
echo"<a href=\"payment.php\">ชำระเงิน</a>\n";
echo"</div>\n";
include("cart_bottom.php");
}
include("closeDB.php");
?>
Tag : - - - -
|
|
|
|
|
|
Date :
5 มี.ค. 2551 16:07:04 |
By :
sakdalll |
View :
1796 |
Reply :
0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|