getConfig('forceAction')) { case 'view': throw new Exception('Product view page not supported'); case 'list': // break omitted intentionally default: if (Qs_Request::isXmlHttpRequest() && in_array($action = Qs_Request::getRequestValue('action'), $this->_actions) ) { $this->_action = $action; break; } if (!empty($this->_restParams)) { if (!$this->_getDataObj()->setCategoryByAlias($this->_restParams)) { $this->_doc->display404(); } } $this->_action = 'list'; break; } return $this; } protected function _hasSubCategories() { $categoryId = $this->_getDataObj()->getCategoryId(); $categoryObj = new App_ECommerce_Product_Category_Obj(); $tree = $categoryObj->getCategoryTree(); $node = $categoryObj->getNode($tree, $categoryId); return ($node['productsCount'] || $node['subcategoriesProductsCount']); } protected function _getOrderFormOptions() { $options = array( 'method' => 'get', 'id' => strtolower($this->getApplicationName()) . '-order-form', 'class' => 'sorter_form clearfix', ); return $options; } protected function _getOrderForm() { if (null === $this->_orderForm) { $this->_orderForm = $this->_getFormInstance('order', $this->_getOrderFormOptions()); } return $this->_orderForm; } protected function _getList() { parent::_getList(); $orderForm = $this->_getOrderForm(); if ($orderForm->isSubmitted() && $orderForm->validate()) { $orderValues = $orderForm->getValues(); $this->_list->setOrderId((int) $orderValues['orderId']); $this->_list->addUrlVariables(array_keys($orderValues)); } $this->_doc->addScript('js/jquery.defaultHint.js'); return $this->_list; } protected function _addListItem($list = null) { $item = $this->_getListItem($list); $item['layoutStandard'] = App_ECommerce_Product_Category_Abstract_Obj::PRODUCT_STANDARD_TYPE_ID; $item['layoutCustom'] = App_ECommerce_Product_Category_Abstract_Obj::PRODUCT_CUSTOM_TYPE_ID; $item['productBaseUrl'] = static::getViewUrl(); $galleryObj = new App\Gallery\Obj(); $item['headerTemplate'] = $this->getTemplate('list-header.tpl'); $item['galleryUrl'] = Qs_SiteMap::findFirst(['enabled' => 'y'], ['type' => 'Gallery\\'], null, 'url'); $item['categoryImages'] = $galleryObj->getAlbumItems($this->_getDataObj()->getCategoryId(), 3); $item['category'] = $this->_getCategory()->getData(); $imageConfig = Qs_Config::getByClass('App\\Gallery\\View')->get('frontendImage', [])->toArray(); $galleryType = $this->_getCategory()->getData('albumOrientation'); $item['imageConfig'] = isset($imageConfig[$galleryType]) ? $imageConfig[$galleryType] : $imageConfig; $item['list'] = $this->_prepareProductList($item); $this->_addLinksItem(); $this->_addItem($item); return $this; } protected function _prepareProductList($item) { if (count($item['category']['sizes']) > 1) { /* group product list by sign Shape (type A)*/ $result = Qs_Array::group($item['list'], ['shapeId', Qs_Array::AUTOINCREMENT]); foreach ($result as &$shapeList) { $shapeList = array( 'groupImage' => array( 'title' => reset($shapeList)['shapeTitle'], 'image' => reset($shapeList)['shapeImage'] ), 'colors' => Qs_array::fetchCol($shapeList, 'colorId', Qs_Array::FETCH_UNIQUE), 'sizes' => Qs_array::fetchCol($shapeList, 'sizeId', Qs_Array::FETCH_UNIQUE), 'list' => Qs_Array::group($shapeList, ['colorId','sizeId']), ); } } else { /* group product list by sign Size (type B)*/ $result = Qs_Array::group($item['list'], ['sizeId', Qs_Array::AUTOINCREMENT]); foreach ($result as $sizeId => &$sizeList) { $sizeList = array( 'groupImage' => array_slice($item['category']['shapes'], 0, 2), 'size' => array('sizeTitle' => $item['category']['sizes'][$sizeId]['title']), 'shapes' => Qs_array::fetchCol($sizeList, 'shapeId', Qs_Array::FETCH_UNIQUE), 'colors' => Qs_array::fetchCol($sizeList, 'colorId', Qs_Array::FETCH_UNIQUE), 'list' => Qs_Array::group($sizeList, ['colorId', 'shapeId']), ); } } return $result; } protected function _doList() { if (!empty($this->_restParams)) { $categoryId = $this->_getDataObj()->getCategoryId(); if (null === $this->_categoryObj) { $this->_categoryObj = new App_ECommerce_Product_Category_Obj(); } $categoryNode = $this->_categoryObj->getNode($this->_categoryObj->getCategoryTree(), $categoryId); if (!$categoryNode) { $this->_do404(); } $this->_doc->addScript('js/app/ECommerce/product/list.js'); $this->_doc->addScript('js/app/ECommerce/product/color-select.js'); $this->_doc->addInitObject('App_Product_Color_Select'); $this->_doc->addScript('js/lib/form.js'); parent::_doList(); } return $this; } /** * @param int $categoryId * @return bool */ protected function _isCategoryVisible($categoryId) { if (null === $this->_categoryObj) { $this->_categoryObj = new App_ECommerce_Product_Category_Obj(); } return (bool) $this->_categoryObj->getNode($this->_categoryObj->getCategoryTree(), $categoryId); } protected function _getCategory() { if (null === $this->_productCategory) { $this->_productCategory = new App_ECommerce_Product_Category_Obj; $this->_productCategory->setPrimaryKey($this->_getDataObj()->getCategoryId()); } return $this->_productCategory; } protected function _getListItem($list = null) { $item = parent::_getListItem($list); if ($this->_listItemTemplate) { $item['tpl'] = $this->_listItemTemplate; } return $item; } protected function _setProductCategory() { $productCategories = $this->_getDataObj()->getData('categories'); $changedCategory = App_ECommerce_Product_Category_View::getCategoryId(); $productChangedCategory = App_ECommerce_Product_Category_View::getCategoryId($this->_restAlias); if (!in_array($changedCategory, $productCategories) && empty($productChangedCategory)) { $changedCategory = current($productCategories); } elseif (!in_array($changedCategory, $productCategories)) { $changedCategory = $productChangedCategory; } if ($productChangedCategory != $changedCategory) { $productChangedCategory = $changedCategory; } App_ECommerce_Product_Category_View::saveCategoryId($productChangedCategory, $this->_restAlias); return $this; } public function getAddToCartForm($formType = 'simple', $productId = null) { if (null === $this->_cartForm) { if ($productId) { $this->_getDataObj()->setPrimaryKey($productId); } $cartItem = Qs_SiteMap::findFirst(null, array('type' => 'ECommerce_Cart_'), array('type' => 'default')); $this->_cartForm = false; if (!empty($cartItem)) { $cartFormOptions = array( 'method' => 'post', 'action' => $this->url(), 'attribs' => array( 'id' => 'cart-form-' . $formType, 'class' => 'cart_form', ), 'defaults' => array( 'productId' => $this->_getDataObj()->getPrimaryKey(), 'quantity' => 1 ), 'formType' => $formType, 'showAdditionalFields' => ($this->_getDataObj()->getData('showAdditionalFields') == 'y') ); $this->_cartForm = new App_ECommerce_Cart_Form_AddItem($cartFormOptions); $this->_cartForm->setDefaults(); if ($formType === 'full') { $this->_cartForm->setScriptOption( 'onSuccessCallback', array('fn' => 'App_Product_View_AddItem.onSuccessAddItem', 'args' => $this->_cartForm->getId()) ); } } } return $this->_cartForm; } protected function _doGetAddToCartFormAjax() { $product = new App_ECommerce_Product_Obj(); $product->setPrimaryKey((int) Qs_Request::getRequestValue('productId')); $form = $this->getAddToCartForm('full', (int) Qs_Request::getRequestValue('productId')); $this->_displayJson(array( 'form' => $this->_renderAddToCartForm($form, $product), )); } /** * @param Qs_Form $form * @param App_ECommerce_Product_Obj $product * @param bool $new * @param array $values * @return string */ protected function _renderAddToCartForm($form, $product, $new = true, $values = []) { Qs_Smarty_File::setTemplate('ECommerce/Product/add-to-cart.tpl'); $errors = []; $descriptions = []; foreach ($form->getElements() as $name => $element) { /** @var $element Zend_Form_Element */ $errors[$name] = $element->getMessages(); $descriptions[$name] = $element->getDescription(); } return Qs_Smarty_File::render([ 'product' => $product->getData(), 'action' => CURRENT_PAGE, 'method' => $form->getMethod(), 'errors' => $errors, 'descriptions' => $descriptions, 'values' => array_merge($form->getValues(), array_filter($values)), 'controllerAction' => $new ? 'addItem' : 'updateNumbers', 'new' => $new, 'cartItemId' => Qs_Request::getRequestValue('cartItemId'), ]); } public function renderCartForm($form = null) { $cartItemData = $this->_getDataObj()->getCartItem(Qs_Request::getRequestValue('cartItemId')); $productId = Qs_Array::get($cartItemData, 'productId'); if (null === $form) { $form = $this->getAddToCartForm('full', $productId); } $product = $this->_getDataObj(); $product->setPrimaryKey($productId); $values = Qs_Request::isPost() ? Qs_Request::getPost() : $cartItemData; $values['numbersFile'] = $cartItemData['numbersFile']; return $this->_renderAddToCartForm($form, $product, false, $values); } protected function _doAddItemAjax() { $form = $this->getAddToCartForm('full'); $data = Qs_Request::getPost(); if (!isset($_FILES['numbersFile'])) { unset($data['numbersFile']); } if ($form->validate() && $this->_addToCart($data)) { $result['success'] = true; $result['quantity'] = $this->_getCart()->getItemsCount(); $result['message'] .= self::MESSAGE_ITEM_HAS_ADDED . ' View Shopping Cart >'; } else { $this->_getDataObj()->setPrimaryKey($data['productId']); $result['success'] = false; $result['form'] = $this->_renderAddToCartForm($form, $this->_getDataObj(), true, $data); $result['errors'] = $form->validateAjax(); } $this->_displayJson($result); } protected function _postAddItem() { $this->_log(); return $this; } }