_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([ 'productId' => $this->_getDataObj()->getPrimaryKey(), 'cartItemType' => \App\ECommerce\Product\Entity::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')) ) { $result = [ 'message' => App_ECommerce_Cart_View::getMessage( App_ECommerce_Cart_View::MESSAGE_ITEM_HAS_UPDATED), 'type' => 'message', ]; } else { $result = [ '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['cartItemType'] = \App\ECommerce\Product\Entity::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 = [ 'message' => App_ECommerce_Cart_View::getMessage(App_ECommerce_Cart_View::MESSAGE_ITEM_HAS_ADDED), 'type' => 'message', ]; } } else { $result = [ '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, ['type' => 'ECommerce_Product_'], ['forceAction' => 'view'], 'url' ); return $url; } /** * @param int $categoryId * @return bool */ protected function _isCategoryVisible($categoryId) { /** * @TODO: переробити все нафіг! зробити тригер який при enable/disable категорії буде рекурсивно проставля її * підкатегоріям відповідне значення enable/disable. */ if (null === $this->_categoryObj) { $this->_categoryObj = new App_ECommerce_Product_Category_Obj(); } static $cache = []; if (null === Qs_Array::get($cache, $categoryId)) { $cache[$categoryId] = (bool) $this->_categoryObj->getNode($this->_categoryObj->getCategoryTree(), $categoryId); } return $cache[$categoryId]; } /** * @param array|null $product * @return bool */ protected function _isProductVisible($product) { if (!empty($product)) { static $storeEnabled; if (null === $storeEnabled) { $storeEnabled = Qs_SiteMap::findFirst( null, ['type' => 'ECommerce_Product_'], ['forceAction' => 'list'], 'enabled' ); } if ('y' != $storeEnabled) { return false; } foreach ($product['categories'] as $categoryId) { if ($this->_isCategoryVisible($categoryId)) { return true; } } } return false; } }