简体   繁体   English

我的代码有什么问题。 我想在现有商品的购物车中添加新商品

[英]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.

相关问题 我不知道我的代码php中有什么问题如果购物车中只有1个项目可以正常工作,但是如果许多项目不能正常工作 - I dont know whats wrong in my code php If only 1 item in cart works properly but if many not working properly 从我的购物车中删除商品。 代码删除第二个项目时会删除错误的项目 - Deleting an item from my shopping cart. Code deletes wrong item when deleting 2nd item 如何将每个产品作为新商品添加到购物车 - How can I add every product as a new item into cart 将项目添加到购物车 - add item into add cart 当我在代码中单击添加到购物车时,我得到的值相同。 这是PHP中的ajax响应 - I am getting the same value when I click on add to cart in my code. It's an ajax response in php 在 Magento 中添加新项目之前清除购物车中的现有项目 - Clear existing items in cart before adding a new Item in Magento shopp插件添加具有自定义价格的现有购物车项目 - shopp plugin add existing cart item with custom price 自定义Woocommerce购物车添加的商品计数有误 - Custom Woocommerce cart add has wrong item count 我无法将商品添加到购物车,为什么? 试图获得非对象的属性“产品” - I can't add an item to my cart, why? Trying to get property 'products' of non-object 我的SQL代码怎么了 - Whats wrong with my sql code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM