Я думаю проблема не js, а в switch....
подскажите как изменить функции по обработки корзины:
function add_to_cart($id){
$id = $_GET['id'];
if(isset($_SESSION['cart'][$id])){
$_SESSION['cart'][$id]++;
return true;
} else{
$_SESSION['cart'][$id] = 1;
return true;
}
return false;
}
function db_result_array($result){
$res_array = array();
$count = 0;
while($row = mysql_fetch_array($result)){
$res_array[$count] = $row;
$count++;
} return $res_array;
}
function get_product($id){
$query = " SELECT * FROM `product` WHERE `id` = '$id'";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
return $row;
}
function update_cart(){
foreach($_SESSION['cart'] as $id => $qty){
if($_POST[$id] == '0'){
unset($_SESSION['cart'][$id]);
} else { $_SESSION['cart'][$id] = $_POST[$id]; }
}
}
function total_items($cart){
$num_items = 0;
if(is_array($cart)){
foreach($cart as $id => $qty){
$num_items = $num_items + $qty;
}
}
return $num_items;
}
function total_price($cart){
$total_price = 0;
if(is_array($cart)){
foreach($cart as $id => $qty){
$query = "SELECT cena FROM product WHERE id = '$id'";
$result = mysql_query($query);
if($result){
$item_price = mysql_result($result, 0, 'cena');
$total_price = $total_price + $item_price * $qty;
}
}
}
return $total_price;
}
Чтоб удалить из кода в этот swith:
switch($page){
case('add_to_cart'):
$id = $_GET['id'];
$add_item = add_to_cart($id);
$_SESSION['total_items'] = total_items($_SESSION['cart']);
$_SESSION['total_price'] = total_price($_SESSION['cart']);
header('Location:/?page=cart');
break;
case('update_cart'):
update_cart();
$_SESSION['total_items'] = total_items($_SESSION['cart']);
$_SESSION['total_price'] = total_price($_SESSION['cart']);
header('Location:/?page=cart');
}