|
 |
|
รบกวนช่วยดูโค้ด Shopping Cart ที่สามารถ Customize สินค้าได้ครับ |
|
 |
|
|
 |
 |
|
คุณแค่ไป Update ตัว Session ใตำแหน่งของ Qty น่ะครับ 
|
 |
 |
 |
 |
Date :
2014-04-29 09:33:30 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คือปัญหาตอนนี้ไม่ใช่เรื่องจำนวนอะครับ แต่เป็นเวลาที่ต้องการเลือกเมนูนี้แต่คนละวัตถุดิบ มันจะไม่สร้างบรรทัดใหม่ให้ แต่จะไป + ของเดิม และแสดงราคาไม่ถูกต้อง เพราะวัตถุดิบในเมนูเดียวกันแต่คนละอย่างจะคนละราคาครับ
ที่คิดๆไว้เบื้องต้นคือจะสร้างเซสชั่นใหม่ไว้เก็บค่า m_id + ingre_id แล้วเอาไว้เช็ค แต่ยังงๆ อยู่เลยครับ - *-
|
 |
 |
 |
 |
Date :
2014-04-29 09:48:48 |
By :
นัส |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เพื่อความไม่สับสนดูรูปนี้ก็ได้ครับ ถ้าเลือกเมนูเดียวกันแต่คนละราคา มันดันไปใส่ไว้อันเดียวกัน ไม่แสดงค่า ingree_id ใหม่และก็คูณผิด (ใช้ราคาเดิม) ที่อยากให้เป็นคือสร้าง intLine ใหม่ครับ ติดตรงวิธีเชคนี่แหละ

|
 |
 |
 |
 |
Date :
2014-04-29 10:10:00 |
By :
นัส |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?
require("config.inc.php");
ob_start();
$mg_no = $_GET['mg_no'];
$page = $_GET['page'];
if(!isset($_SESSION["intLine"]))
{
$_SESSION["intLine"] = 0;
$_SESSION["strProductID"][0] = $_GET['m_id'];
$_SESSION["strIngreID"][0] = $_POST['ingre']; // บรรทัดที่เพืม
$_SESSION["strQty"][0] = 1;
header("location:menu.php?mg_no=$mg_no&page=$page");
}
else
{
// เอา 2 บรรทัดนี้ออกเลยครับ ถ้าอยากให้ขึ้นบรรทัดใหม่ มันจะมองสินค้าเป็นคนละตัวกัน //
/*
$key = array_search($_GET['m_id'], $_SESSION["strProductID"]);
$key2 = array_search($_GET['ingre'], $_SESSION["strIngreID"]);
//if ($key != "" && $key2 != "")
if ((string)$key != "")
{
$_SESSION["strQty"][$key] = $_SESSION["strQty"][$key] + 1;
}
else
{
/*
เสร็จแล้วก็เขียน ตรวจสอบ ว่า ตะกร้าสินค้าที่มี ตรงกับที่เลือกเข้ามาหรือยัง
if($_SESSION["strProductID"]==$_POST['productID']){
ถ้ามันมีอยู่แล้วก็ให้มันเช็คอีกรอบว่า รายการย่อย มีหรือยัง
if($_SESSION["strIngreID"]==$_POST['strLngreID']){
$_SESSION["strQty"][$key] = $_SESSION["strQty"][$key] + 1; ถ้ามีแล้วก็ให้ + 1
}
}
พอดีเขียนลวกๆไม่ได้ทดสอบ คุณเอาไปดัดแปลงเองนะครับ
$_SESSION["intLine"] = $_SESSION["intLine"] + 1;
$intNewLine = $_SESSION["intLine"];
$_SESSION["strProductID"][$intNewLine] = $_GET['m_id'];
$_SESSION["strIngreID"][$intNewLine] = $_POST['ingre']; // บรรทัดที่เพืม
$_SESSION["strQty"][$intNewLine] = 1;
#}
header("location:menu.php?mg_no=$mg_no&page=$page");
}
?>
|
 |
 |
 |
 |
Date :
2014-04-29 10:18:39 |
By :
Dragons_first |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทำได้แล้วครับ !!! 
ลองแนวทางของพี่ข้างบนแล้วไม่เวิร์คครับ เพราะค่า 2 ตัวถูกดึงมาจาก 2 ตารางซึ่งอาจเป็นไปได้ว่าเคบมีการ add ทั้ง 2 ค่า จาก คนละเมนู ผลเลยยังเพี้ยนๆครับ
วิธีการที่ผมใช้ ง่ายสุดเลยคืนเลิกสนใจ ID เก่า สร้างใหม่ โดยเอาสองค่ามาต่อกัน ทีนี้มันก็ยูนีคแว้ว เย่ๆๆๆ
เอาโค้ดที่แก้มาฝากครับ เผื่อใครอยากลองทำแนวนี้ แก้นิดเดียวเอง งมอยู่ตั้งนาน 
Code (PHP)
<?
require("config.inc.php");
ob_start();
$mg_no = $_GET['mg_no'];
$page = $_GET['page'];
$checkM = $_GET['m_id'].$_POST['ingre']; // สร้างเพื่อตรวจ
if(!isset($_SESSION["intLine"]))
{
$_SESSION["intLine"] = 0;
$_SESSION["strProductID"][0] = $_GET['m_id'];
$_SESSION["strIngreID"][0] = $_POST['ingre']; // บรรทัดที่เพืม
$_SESSION["strQty"][0] = 1;
$_SESSION["strCheck"][0] = $checkM; //***เก็บค่าใหม่
header("location:menu.php?mg_no=$mg_no&page=$page");
}
else
{
//$key = array_search($_GET['m_id'], $_SESSION["strProductID"]);
$keycheck = array_search($checkM, $_SESSION["strCheck"]);
//if ((string)$key != "")
//if ($_SESSION["checkM"] == $_GET['m_id'].$_POST['ingre'])
if ((string)$keycheck != "")
{
//$_SESSION["strQty"][$key] = $_SESSION["strQty"][$key] + 1;
$_SESSION["strQty"][$keycheck] = $_SESSION["strQty"][$keycheck] + 1;
}
else
{
$_SESSION["intLine"] = $_SESSION["intLine"] + 1;
$intNewLine = $_SESSION["intLine"];
$_SESSION["strProductID"][$intNewLine] = $_GET['m_id'];
$_SESSION["strIngreID"][$intNewLine] = $_POST['ingre']; // บรรทัดที่เพืม
$_SESSION["strQty"][$intNewLine] = 1;
$_SESSION["strCheck"][$intNewLine] = $checkM; ///****
}
header("location:menu.php?mg_no=$mg_no&page=$page");
}
?>
Code (PHP)
<style type="text/css">
.jkfgjkfkfg {
text-align: right;
}
</style>
<center><font size=-1>
<table width="285" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2"><img src="images/shopping_cart.png" /></td>
</tr>
<tr>
<td colspan="2"><?
session_start();
require ("connect_sql.php");
//require("config_detail.inc.php");
$Total = 0;
$SumTotal = 0;
for($i=0;$i<=(int)$_SESSION["intLine"];$i++)
{
//if($_SESSION["strProductID"][$i] != "")
if($_SESSION["strCheck"][$i] != "")
{
$strSQL = "SELECT * FROM m_menu_tb JOIN m_ingredient_tb WHERE m_id = '".$_SESSION["strProductID"][$i]."' AND ingre_id ='".$_SESSION["strIngreID"][$i]."' ";
$objQuery = mysql_query($strSQL) or die(mysql_error());
$objResult = mysql_fetch_array($objQuery);
$Total = $_SESSION["strQty"][$i] * $objResult["i_price"];
$SumTotal = $SumTotal + $Total;
$price = $objResult["i_price"];
?>
<center><table width="95%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="80%" valign="top"><span style='border-bottom:#000 1px dotted'><? //=$_SESSION["strProductID"][$i];?><?=$objResult["m_name"];?></span> (<?=number_format($price,0);?>x<?=$_SESSION["strQty"][$i];?>)<br/> : <?=$objResult["i_name"];?></td>
<td width="14%" align="right" valign="top" class="jkfgjkfkfg"><?=number_format($Total,0);?><br /><br /></td>
<td width="6%" valign="top"><a href="delete.php?<? echo "mg_no=".$mg_no."&page=".$page ?>&Line=<?=$i;?>"><img src="images/icon_delete_16x16.png" border="0" title ="นำออกจากรายการ"/></a></td>
</tr>
<?
}
}
?>
</table> </center>
</td>
</tr>
<tr>
<td width="56%">
<?
if($SumTotal > 0)
{
?><hr>
<b>Total:
<font size=+1><?=number_format($SumTotal,2); echo $curency; ?> </font>
</b><br /></td>
<td width="44%">
<a href="checkout.php"><br /><img src="images/feature-head-checkout1.png" border="0" title = "ไปหน้าสรุปการสั่งซื้อ" /></a>
</td>
</tr>
<tr>
<td colspan="2" align="center"><br><font size=-1>หลังจากคลิกจะมีหน้าให้ยืนยันอีกรายการครั้งค่ะ *</font></td>
</tr>
</table>
<? } mysql_close(); ?>
</center>
<!--
</body>
</html> -->
Code (PHP)
<?
$mg_no = $_GET['mg_no'];
$page = $_GET['page'];
ob_start();
session_start();
$Line = $_GET["Line"];
//$_SESSION["strProductID"][$Line] = "";
$_SESSION["strCheck"][$Line] = "";
$_SESSION["strQty"][$Line] = "";
header("location:menu.php?mg_no=$mg_no&page=$page");
?>
โค้ดเก่า ผมยัง Comment ไว้นะครับ ดูเทียบกันได้เลย ^^
|
 |
 |
 |
 |
Date :
2014-04-29 12:05:09 |
By :
นัส |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|