1
장바구니 행 ID가 product_id 인 장바구니를 만들려고하는데 다음과 같이해야합니다. 장바구니에 두 개의 동일한 제품을 입력 할 수 있지만 너비가 다른 색 속성 . 폭 폼 포스트 나는 'id'와 'color'를 게시합니다. 지금까지 코드 :하나의 제품에 2 행이있는 장바구니 작성
<?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!";
}
}
}
?>