doutun9179
2013-01-25 11:07
浏览 18
已采纳

更新会话数组+ zf2的节点

First I added a session then I print my session it looks completely ok here it is

Array
(
[14] => Array//(main key is my restaurant Id)
    (
        [retaurantDetail] => Array
            (
                [restId] => 14
                [restaurantName] => Barca
                [published] => 1
                [timings] => 10 to 10
                [normalCost] => 150
                [logo] => 44f7afcffb0aeea5c69ccee9041cab84.jpg
                [email] => barca@barca.com
                [phone] => 741258
            )

        [menuArray] => Array
            (
                [70] => Array // (menu ID is the Key)
                    (
                        [menuId] => 70
                        [productId] => 35
                        [productName] => Coca Cola
                        [categoryTitle] => Beverages
                        [categoryId] => 52
                        [price] => 100
                        [attributeName] => 1.5L
                        [isDefault] => 1
                        [qty] => 1
                    )

            )

    )
)

Now I add some logic if some one add again that menu in add to cart in short he/she adds plus 1 qty to that menu here it is my code,(code is not completed yet but now I am focused on just to update qty)

            foreach($session->cartSession as $sessionKey=>$sessionVal)
            {

                        foreach($sessionVal['menuArray'] as $sessionMenuKey=>$sessionMenuVal)
                        {

                            if($sessionMenuKey == $post_data['menuId'])
                            {
                                echo"<pre>"; print_r($sessionMenuVal['qty']); echo "</pre>";
                                //$qty = $session->cartSession[$restaurantDetail['restId']]['menuArray'][$sessionMenuKey];
                                $sessionMenuVal['qty'] =  $sessionMenuVal['qty']+1;

                                echo"<pre>"; print_r($sessionMenuVal['qty']); echo "</pre>"; 

                            }

                         }
            }

What I am missing I want to updatre session qty.

every time I press add it shows 1 qty then I add plus 1 qty to it then it show 2 after then it again shows 1 qty :(.

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题