0

ゼンド初心者です。zend_sessionをいじると、このような問題が発生しました。

1つのアイテムですべてがうまく機能します。ただし、複数のアイテムがあると、アイテムの追加が停止するか、一致するアイテムが増えます。

ここに私のコードがあります

// 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;
            }
4

1 に答える 1

0

最初のカート項目の ID のみをテストしているようです:

if($productSessionArray['product_id'] == $cartArrays[0]['product_id'] && $productSessionArray['product_size_title'] == $cartArrays[0]['product_size_title'])
于 2013-03-22T10:15:11.103 に答える