
richie
Kezdő
|
Sziasztok,
Egy tutorial alapjan keszitettem egy shopping cart-ot, ami mukodik tokeletesen, egy problemam van, hogy nem tudok plus funkciot hozza adni.
A shopping cart egy italian etteremhez fog tartozni. Tokeletesen kosarba tudom tenni a termekeket, majd fizettetni blabla..
Az en elakadasom:
Kilistazom a tesztakat "add button"-al, de nekem az is kell, hogy mindegyik teszta etelhez tartozon egy "radio" vagy "checkbox" lehetoseg "add chicken X osszeg", es ha vevo jeloli, akkor az bekeruljon a kosarba, de csak a valasztott teszta etelhez.
Pl:
Pomodorro x1 £10.00
Alla'Italiana x1 £11.00
add chicken x1 £1.50
Gorgonzola x2 £22.00
add chicken x1 £1.50
Ha nezed a listat feljebb, akkor lathatod, hogy peldaul "gorgonzola" 2x valasztva, de csak egyikhez kernek chicken-t csak.
Ezt nem tudom, hogyan kivitelezni, tudnatok ebben a segitsegemre lenni?
Alabbi code all rendelkezesemre.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
<?
ob_start();
session_start();
include('connect.php');
// add item(s) shopping cart
if (isset($_POST['product_id'])) {
$pid = $_POST['product_id'];
$wasFound = false;
$i = 0;
if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) {
$_SESSION["cart_array"] = array(0 => array("item_id" => $pid, "quantity" => 1, "quantity" => 1));
}
else {
foreach ($_SESSION["cart_array"] as $each_item) {
$i++;
while (list($key, $value) = each($each_item)) {
if ($key == "item_id" && $value == $pid) {
array_splice($_SESSION["cart_array"], $i-1,1,array(array("item_id" => $pid, "quantity" => $each_item['quantity']+1)));
$wasFound = true;
}
}
}
if ($wasFound == false) {
array_push($_SESSION["cart_array"], array("item_id" => $pid, "quantity" => 1));
}
}
}
// empty shopping cart
if (isset($_GET['cmd']) && $_GET['cmd'] == "emptycart") {
unset($_SESSION["cart_array"]);
}
// remove item(s) shopping cart
if (isset($_POST["index_to_remove"])&& $_POST["index_to_remove"]!="") {
$key_to_remove = $_POST["index_to_remove"];
if(count($_SESSION["cart_array"]) <= 1) {
unset($_SESSION["cart_array"]);
}
else {
unset($_SESSION["cart_array"]["$key_to_remove"]);
sort($_SESSION["cart_array"]);
}
}
// render shopping cart
$cartOutput = "";
$cartTotal = "";
if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) {
$cartOutput = "Your order cart is empty";
}
else {
$i = 0;
foreach($_SESSION["cart_array"] as $each_item) {
$item_id = $each_item['item_id'];
$sql= mysql_query("SELECT * FROM `product` WHERE `item_id`='$item_id' LIMIT 1");
while ($row = mysql_fetch_array($sql)) {
$item_name = $row["item"];
$item_price = $row["price"];
$item_plus = $row["plus"];
$item_price2 = $row["price2"];
$item_category = $row["category"];
}
$price = $item_price * $each_item['quantity'];
$cartTotal = $price + $cartTotal;
$cartOutput.= '<table width="229" cellspacing="0" cellpadding="0"><tr>';
$cartOutput.= '<td width="150" align="left">('.$item_category.') '.$item_name.'</td>';
$cartOutput.= '<td align="right" width="20">x'.$each_item["quantity"].'</td>';
$cartOutput.= '<td align="right">£'.$english_format_number = number_format($price, 2, ".", "").'</td>';
$cartOutput.= '<td align="right"><form action="?p=cart" method="post"><input type="submit" name="deleteBtn'.$item_id.'" class="remove" value="x">';
$cartOutput.= '<input type="hidden" name="index_to_remove" value="'.$i.'"></form></td></tr></table>';
$i++;
}
}
echo $cartOutput;
//echo "<table width="229"><tr><td align="center"><a href="?p=cart&cmd=emptycart">Empty Cart</a></td></tr></table>";
echo $english_format_number = number_format($cartTotal, 2, '.', '');
ob_end_flush();
?>
|
Elore is koszonok minden segitseget.
Udv.: Richie
Utoljára szerkesztette: richie 2013.07.17. 17:33
richie
|