Zend framework zend_会话在获得第二个产品后出错

Zend framework zend_会话在获得第二个产品后出错,zend-framework,zend-session,zend-session-namespace,Zend Framework,Zend Session,Zend Session Namespace,我是一个天才。当我在zend_会议上乱搞的时候,我遇到了这样的问题 有了一个项目,一切都很好。 但不止一个项目会停止添加更多项目或增加匹配项目 这是我的密码 // get value from form $intQuantity = $this->_request->getPost ( 'intQuantity' ); $intSize = $this->_request->getPost ( 'intSize' );

我是一个天才。当我在zend_会议上乱搞的时候,我遇到了这样的问题

有了一个项目,一切都很好。 但不止一个项目会停止添加更多项目或增加匹配项目

这是我的密码

// get value from form
            $intQuantity = $this->_request->getPost ( 'intQuantity' );
            $intSize = $this->_request->getPost ( 'intSize' );
            $intProductId = $this->_request->getParam('productId');
            //call model cart
            $cartModel = new Default_Model_cart();

            //input value into cartModel function addItem output array of matched row
            /*
             * Array
            *   (
            *       [0] => Array
            *           (
            *               [product_id] => 7
            *               [product_price] => 1600000
            *               [product_image_url_50] => 50_nike-janoski-new-1363618892.jpg
            *               [product_size_title] => 6.5
            *           )
            *   )
             * 
             * 
             * */
            $cartArrays = $cartModel->addItem($intProductId, $intQuantity, $intSize);

            //add quantity into cartArrays
            /*
             * Array
            *   (
                    *       [0] => Array
                    *           (
                            *               [product_id] => 7
                            *               [product_price] => 1600000
                            *               [product_image_url_50] => 50_nike-janoski-new-1363618892.jpg
                            *               [product_size_title] => 6.5
                            *               [quantity] => 1
                            *           )
                    *   )
            *
            *
            * */
            $cartArrays[0]['quantity'] = $intQuantity;
            //declare session
            $session = new Zend_Session_Namespace();
            /*
             * if true session->product got at least one array of of cartArray
             * */
            if(isset($session->product)) {
                $i=0;
                //foreach arrays into array
                foreach($session->product as $productSessionArray) {
                    /*if in an array got productId and product_size_title matched cartArrays productId and product_size_title
                    * add value from $intQuantity into appropriate $session->product determined by $i
                    */ 
                    if($productSessionArray['product_id'] == $cartArrays[0]['product_id'] && $productSessionArray['product_size_title'] == $cartArrays[0]['product_size_title']) {
                        $session->product[$i]['quantity'] += $intQuantity;
                        /*
                         * if values don't matched add the whole new array into $session->product
                         * */
                    } else {
                        $productSessionArrays[] = $productSessionArray;
                        $productSessionArrays[] = $cartArrays[0];
                        $session->product = $productSessionArrays;
                    }
                    //$i increase by 1
                    $i++;
            }
                //if there is not an array in $session added the array in to it
            } else {
                $session->product = $cartArrays;
            }

看起来您只是在测试第一个购物车项目的id:

if($productSessionArray['product_id'] == $cartArrays[0]['product_id'] && $productSessionArray['product_size_title'] == $cartArrays[0]['product_size_title'])