我尝试保存购物车数组以完成订单,然后从客户处获取关于订单的日期。我做了一些东西,但效果不好,首先是在页面confirm_comanda.php
上向我展示最后一个数组的数组日期,例如我在购物车会话中有3个产品,正在带我product_name
{{ 1}}用于最后一个数组产品。只有price
向我展示,最终价格为quanty
totalCOMANDApret
隐藏的表单,用于从购物车数组中选择的产品中获取会话数组日期
// Start the For Each loop
$i = 0;
foreach ($_SESSION["cart_array"] as $each_item) {
$item_id = $each_item['item_id'];
// start select query stmt
$stmt = $con->prepare('SELECT id, product_name, price, size, details FROM products WHERE id = ? LIMIT 1');
$stmt->bind_param('i', $item_id);
$stmt->execute();
$stmt->bind_result($idSelect, $product_name, $price, $size, $details);//variabla pe care o vrei inlocuita prin bind_Result in loc de get_Result
while ($stmt->fetch()) {
$idSelect;
$product_name; // faci acelasi lucru fara $row
$price;
$size;
$details;
}
$stmt->free_result();
// stoop select stmt
$pricetotal = $price * $each_item['quantity'];
$cartTotal = $pricetotal + $cartTotal;
// Create the product array variable
$product_id_array .= "$item_id-".$each_item['quantity'].",";
// Dynamic table row assembly
$cartOutput .= "<tr>";
$cartOutput .= '<td><a href="product.php?id=' . $item_id . '">' . $product_name . '</a><br /><img src="inventory_images/' . $item_id . '.jpg" alt="' . $product_name. '" width="100" height="62" border="1" /></td>';
$cartOutput .= '<td>' . $details . '</td>';
$cartOutput .= '<td>' . $price . ' RON</td>';
// How to split a query value into several mutiple rows for a select tag using explode() STAART SIZE
$myArraySize = explode(' ', $size);
$cartOutput .= '<td><form action="cart.php" method="post"><select name="size">';
foreach($myArraySize as $my_ArraySize)
{
$cartOutput .= '<option value="'.$my_ArraySize.'">'.$my_ArraySize.'</option>';
}
$cartOutput .= '</select><input name="quantity" type="text" value="' . $each_item['quantity'] . '" size="1" maxlength="2" />buc
<input name="adjustBtn' . $item_id . '" type="submit" value="change" />
<input name="item_to_adjust" type="hidden" value="' . $item_id . '" />
</form></td>';
//STOP SIZE
//$cartOutput .= '<td>' . $each_item['quantity'] . '</td>';
$cartOutput .= '<td><center>' . $pricetotal . ' RON</center></td>';
$cartOutput .= '<td><form action="cart.php" method="post"><input name="deleteBtn' . $item_id . '" type="submit" value="X" /><input name="index_to_remove" type="hidden" value="' . $i . '" /></form></td>';
$cartOutput .= '</tr>';
页面confirm_comanda.php以确认订单并获取客户开票日期和运费
$cofirmaComanda = '<form action="cofirma_comanda.php" method="post">';
$i=0;
foreach ($_SESSION["cart_array"] as $each_item) { //start second forecach
$cofirmaComanda .='
<input name="prettotal[]" type="hidden" value="'. $pricetotal .'">
<input name="produseID[]" type="hidden" value="'. $item_id .'">
<input name="produseNume[]" type="hidden" value="'. $product_name .'">
<input name="size[]" type="hidden" value="'. $my_ArraySize .'">
<input name="cantitate[]" type="hidden" value="' . $each_item['quantity'] .'">
<input name="produse[]" type="hidden" value="'. $item_id .'">;
<input name="totalCOMANDApret[]" type="hidden" value="'. $cartTotal .'">';
} //close second foreach
$cofirmaComanda .='<input type="submit" name="CofirmaComanda" value="cofirma_comandaTOW"></form>';
}
表单隐藏和表单输入以完成订单
$countArray = count($_SESSION['cart_array']);
for ($i=0; $i<$countArray; $i++) {
$pretTotal = $_POST["prettotal"][$i];
$PRODUSE = $_POST["produseID"][$i];
$produseNume = $_POST["produseNume"][$i];
$size = $_POST["size"][$i];
$cantitate = $_POST["cantitate"][$i];
$total = $_POST["totalCOMANDApret"][$i];
}
我知道是一个完整的代码,但我真的想解决这个问题,脚本的一部分是从一个在线课程,但他们使用paypal,我改变了,因为我想让它更简单