2017-01-27 35 views
-2

我的代碼有什麼問題。我想在車中添加新項目與現有項目我的代碼有什麼問題。我想在購物車中添加新物品,並且現有商品

<?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; 

    } 

    ?> 
+1

有什麼不順心,你用什麼平臺,你得到一個錯誤信息,沒有足夠的信息去解答你的問題。 –

+0

我想添加新項目到購物車。但是沒有將已經存在的新物品放入購物車。我正在使用php – Hemant

回答

0

試試這個

$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); 
+0

謝謝Mànìkàndàn – Hemant

相關問題