1 回答
TA贡献1842条经验 获得超21个赞
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (isset($_POST['do_it']) && $_POST['do_it'] == 'change') {
if (isset($_SESSION['basket'])) {
$is_available = 0;
foreach ($_SESSION['basket'] as $keys => $values) {
if ($_SESSION['basket'][$keys]['product_id'] == $_POST['id']) {
$is_available++;
$_SESSION['basket'][$keys]['product_quantity'] += $_POST['quantity'];
}
}
}
if ($is_available == 0) {
if (!isset($_SESSION['basket'])) {
$_SESSION['basket'] = array();
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (isset($_POST['id'])) {
$_SESSION['basket'][$_POST['id']] = array(
'product_id'=>($_POST['id']),
'product_photo'=>($_POST['hidden_photo']),
'product_photo_alt'=>($_POST['hidden_photo_alt']),
'product_name'=>($_POST['hidden_name']),
'product_price'=>($_POST['hidden_price']),
'product_quantity'=>($_POST['quantity'])
);
}
}
}
}
}
归功于https://www.webslesson.info/2018/04/shopping-cart-by-using-bootstrap-popover-with-ajax-php.html
虽然,我不确定我是否理解$is_available代码中的实际作用以及添加相同产品时它是如何指代增加数量的。
- 1 回答
- 0 关注
- 115 浏览
添加回答
举报