_getCart()->getItem(array('productId' => $this->_getDataObj()->getPrimaryKey())); if ($item) { $numbersText = $this->_prepareNumbersTextData($item['numbersText'], $data['numbersText']); $numbersFile = ($data['numbersFile']) ? $data['numbersFile'] : ($item['numbersFile']) ? $item['numbersFile'] : null; if ($this->_getCart()->updateItemQty( $item['id'], Zend_Locale_Math::Add($item['quantity'], $data['quantity']), $this->_getDataObj()->getData('price'), $this->_getDataObj()->getData('tax'), $numbersText, $numbersFile)) { $result = array( 'message' => App_ECommerce_Cart_View::getMessage( App_ECommerce_Cart_View::MESSAGE_ITEM_HAS_UPDATED), 'type' => 'message' ); } else { $result = array( 'message' => App_ECommerce_Cart_View::getError( App_ECommerce_Cart_View::ERROR_VALIDATE_CART_ITEM_ADD), 'type' => 'error' ); } } //add item if not exist if ($result === false) { $productData = $this->_getDataObj()->getData(); $productData += $data; $productData['type'] = 'ECommerce_Product_'; if ($this->_restAlias) { $productData['productCategoryId'] = App_ECommerce_Product_Category_View::getCategoryId( $this->_restAlias ); } elseif ($productData['categoryId']) { $productData['productCategoryId'] = $productData['categoryId']; } else { $productData['productCategoryId'] = 0; } $this->_getCart()->addItem($productData); $result = array( 'message' => App_ECommerce_Cart_View::getMessage(App_ECommerce_Cart_View::MESSAGE_ITEM_HAS_ADDED), 'type' => 'message' ); } return $result; } protected function _prepareNumbersTextData($oldData, $newData) { $arr = array(); array_push($arr, trim($oldData), trim($newData)); return implode(self::NUMBER_TEXT_DELIMITER, array_filter($arr)); } /** * Return shopping cart object * * @return App_ECommerce_Cart_Obj */ protected function _getCart() { if (null === $this->_cart) { $this->_cart = new App_ECommerce_Cart_Obj(); $this->_cart->setPrimaryKey($this->_cart->getCartId()); } return $this->_cart; } protected function _getLog() { if (null === $this->_log) { parent::_getLog(); $this->_log->setAction('addItem', 'Added "%itemTitle%" %itemName% to the Shopping Cart'); } return $this->_log; } public static function getViewUrl() { $url = Qs_SiteMap::findFirst( null, array('type' => 'ECommerce_Product_'), array('forceAction' => 'view'), 'url' ); return $url; } }