1
我試圖建立購物車,其中車行id是product_id,但我需要它是這樣的:我可以輸入兩個相同的產品購物車,但寬度不同的顏色屬性。寬度表單帖子發佈'id'和'color'。到目前爲止的代碼:建立購物車與兩行爲一個產品
<?php
require('../../../wp-config.php');
mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(isset($_POST['submit'])) {
$id=intval($_POST['id']);
if (isset($_SESSION['cart'][$id]) && $_SESSION['cart'][$id]['color'] == $_POST['color']) {
$_SESSION['cart'][$id]['quantity']++;
$link =str_replace('?action=added_to_cart', '', $_SERVER['HTTP_REFERER']);
header('location:' . $link . '?action=added_to_cart');
} else {
$sql_s="SELECT * FROM wp_posts WHERE ID=($id)";
$query_s=mysql_query($sql_s);
if(mysql_num_rows($query_s)!=0) {
$row_s=mysql_fetch_array($query_s);
if ($_POST['color'] == 'gray') {
$price = get_price($id);
} else {
$price = get_price_colored_stones($id);
}
$_SESSION['cart'][$row_s['ID']]=array(
"quantity" => 1,
"price" => $price,
"color" => $_POST['color']
);
$link =str_replace('?action=added_to_cart', '', $_SERVER['HTTP_REFERER']);
header('location:' . $link . '?action=added_to_cart');
} else {
$message="This product id is invalid!";
}
}
}
?>