0
我曾经为我的网站下载过这个购物车脚本。 但现在我想将值添加到购物车,但无法弄清楚如何... :(
我有下面的代码:
product.php
<form method="post" action="cart.php?action=update">
<div class="quantity">
<input type="text" name="qty<?php echo(''.$pinfo->id.''); ?>" value="1" /><span> χ</span>
</div>
<div class="add-quantity">
<input class="nice-s" type="submit" name="product-quantity-submit" value="ORDER" />
</div>
</form>
cart.php
$cart = $_SESSION['cust_cart'];
if(isset($_GET['action'])) {
$action = sanitize($_GET['action']);
switch ($action) {
case 'add':
if ($cart) {
$cart .= ','.$_GET['id'];
} else {
$cart = $_GET['id'];
}
break;
case 'delete':
if ($cart) {
$items = explode(',',$cart);
$newcart = '';
foreach ($items as $item) {
if ($_GET['id'] != $item) {
if ($newcart != '') {
$newcart .= ','.$item;
} else {
$newcart = $item;
}
}
}
$cart = $newcart;
}
break;
case 'update':
/* if ($cart) { */
$newcart = '';
foreach ($_POST as $key=>$value) {
if (stristr($key,'qty')) {
$id = str_replace('qty','',$key);
$items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart);
$newcart = '';
foreach ($items as $item) {
if ($id != $item) {
if ($newcart != '') {
$newcart .= ','.$item;
} else {
$newcart = $item;
}
}
}
for ($i=1;$i<=$value;$i++) {
if ($newcart != '') {
$newcart .= ','.$id;
} else {
$newcart = $id;
}
}
}
}
/* } */
$cart = $newcart;
break;
}
}
$_SESSION['cust_cart'] = $cart;
我想知道的是,我怎样才能通过product.php页面另一个值添加到购物车与以下字段:
<div class="size">
<select name="size">
<option value="16 INCH">16 INCH</option>
<option value="19 INCH">19 INCH</option>
<option value="22 INCH">22 INCH</option>
</div>
Thanx提前! B)
Thnx,只是作为一个例子,所以忘了关闭选择标签(一直发生在我身上;))我想实现的是将此值添加到购物车。因此,在购物车现在所持有的产品编号为2,数量为$ pinfo-> id的情况下,我希望将其扩展为尺寸。 – Baron85 2012-04-07 16:19:36
@JoeyvanBilsen它的确取决于我们在这里谈论哪个脚本,它们都是以不同的方式编码的,并且在黑暗中说出你应该添加什么来实现这一点。有些脚本允许您在GUI中动态配置类似的选项,因此我建议您阅读脚本的文档并找到一种方法。 – esqew 2012-04-08 07:44:36