_messageTemplates[self::MSG_SOLD_OUT_ADD] = 'Sold Out %itemName% can not be added to shopping cart'; return parent::_init(); } /** * Add or update item in cart * @param array $data * @return array|bool */ protected function _addToCart(array $data) { $result = false; if ($this->_getDataObj()->getData('soldOut') == 'n') { //verify if item exist in cart $item = $this->_getCart()->getItem(array( 'productId' => $this->_getDataObj()->getPrimaryKey(), 'cartItemType' => ProductEntity::CART_ITEM_TYPE )); if ($item) { if ($this->_getCart()->updateItemQty( $item['id'], Zend_Locale_Math::Add($item['quantity'], $data['quantity']), $this->_getDataObj()->getData('price'), $this->_getDataObj()->getData('tax')) ) { $message = App_ECommerce_Cart_View::getMessage(App_ECommerce_Cart_View::MESSAGE_ITEM_HAS_UPDATED); $result = array( 'message' => $message, 'type' => 'message' ); if (Qs_Doc::ANALYTICS_TYPE_GOOGLE_TAG_MANAGER == $this->_doc->getAnalyticsType()) { $eeData = $item; $eeData['quantity'] = $data['quantity']; $result['gtmProduct'] = Qs_Gtm::eeGetProduct($eeData, Qs_Gtm::DATASET_CART); } } else { $message = App_ECommerce_Cart_View::getError(App_ECommerce_Cart_View::ERROR_VALIDATE_CART_ITEM_ADD); $result = array( 'message' => $message, 'type' => 'error' ); } } //add item if not exist if ($result === false) { $productData = $this->_getDataObj()->getData(); $productData += $data; $productData['cartItemType'] = ProductEntity::CART_ITEM_TYPE; $productData['productCategoryId'] = App_ECommerce_Product_Category_View::getCategoryId( $this->_restAlias ); if (empty($productData['productCategoryId'])) { $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' ); if (Qs_Doc::ANALYTICS_TYPE_GOOGLE_TAG_MANAGER == $this->_doc->getAnalyticsType()) { $eeData = $this->_getCart()->getItem(array( 'productId' => $this->_getDataObj()->getPrimaryKey(), 'cartItemType' => ProductEntity::CART_ITEM_TYPE )); $eeData['quantity'] = $data['quantity']; $result['gtmProduct'] = Qs_Gtm::eeGetProduct($eeData, Qs_Gtm::DATASET_CART); } } } else { $result = array( 'message' => $this->_createMessage(self::MSG_SOLD_OUT_ADD), 'type' => 'error' ); } return $result; } /** * 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; } }