[英]Whats wrong with my code. I want to add new item in the cart with the existing item
Whats wrong with my code.我的代码有什么问题。 I want to add new item in the cart with the existing item
我想在现有商品的购物车中添加新商品
<?php
if($_SESSION['shopping_cart']['item'])
{
$dish[0]= array('meal_type'=>$meal_type,'meal_package'=>$meal_package,'meal_time'=>$meal_time,'meal_plan_days'=>$meal_plan_days,'meal_dish_type'=>$meal_dish_type,'prefixed_qty'=>$prefixed_qty,'prefixed_date'=>$prefixed_date,'cart_plan'=>$cart_total,'product_rule'=>$product_rule);
$_SESSION['shopping_cart']['item'] = $dish;
$_SESSION['shopping_cart']['cart_total'] = $cart_total*$prefixed_qty;
}
else
{
$item[]=array('meal_type'=>$meal_type,'meal_package'=>$meal_package,'meal_time'=>$meal_time,'meal_plan_days'=>$meal_plan_days,'meal_dish_type'=>$meal_dish_type,'prefixed_qty'=>$prefixed_qty,'prefixed_date'=>$prefixed_date,'cart_plan'=>$cart_total,'product_rule'=>$product_rule);
$dish=array_push($dish,$item);
$_SESSION['shopping_cart']['item'] = $dish;
$_SESSION['shopping_cart']['cart_total'] = $cart_total*$prefixed_qty;
}
?>
Try this尝试这个
$item[] = array(
'meal_type' => $meal_type,
'meal_package' => $meal_package,
'meal_time' => $meal_time,
'meal_plan_days' => $meal_plan_days,
'meal_dish_type' => $meal_dish_type,
'prefixed_qty' => $prefixed_qty,
'prefixed_date' => $prefixed_date,
'cart_plan' => $cart_total,
'product_rule' => $product_rule
);
$_SESSION['shopping_cart']['item'] = array_merge($_SESSION['shopping_cart']['item'], $item);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.