'list'); protected function _init() { parent::_init(); $this->_loadConfigMessage(self::MSG_NOT_FOUND_REDIRECT); return $this; } public function exec() { $alias = $this->getRestAlias(); if (!empty($alias)) { if ($this->getConfig('type') == 'detail') { $this->_action = 'tree'; } else { $this->_getDataObj()->setCategoryIdByAlias($alias); if (!$this->_getDataObj()->getCategoryId()) { $this->_setBackUrl(Qs_Request::getFinalBaseUrl()); $this->_setBackMessage(self::MSG_NOT_FOUND_REDIRECT); $this->_doBack(); } } } return parent::exec(); } public function _log() { if ($this->_hasLog && Qs_ViewController_Log::getEnabled()) { $options = $this->_getDataObj()->getObjectInfo(); if ('' != $this->getRestAlias()) { $this->_getLog()->write('view', $options); } else { $this->_getLog()->write($this->_action, $options); } } return $this; } protected function _doList() { $dataObj = $this->_getDataObj(); if (($categoryId = $dataObj->getCategoryId())) { $this->_appendNavigation($dataObj->getCategoryTree($categoryId)); $this->_getDataObj()->setPrimaryKey($categoryId); $data = $this->_getDataObj()->getData(); FormMetaTrait::updateMetaKeywords($data); FormMetaTrait::updateMetaDescription($data); } static::saveCategoryId($dataObj->getCategoryId()); $this->_addTreeBlock('LEFT_ITEMS'); return parent::_doList(); } protected function _doTree() { $this->_addTreeBlock(); return $this; } protected function _appendNavigation($branch) { $crumb = array('title' => $branch['title'], 'url' => $branch['url']); Qs_Navigation::append($crumb); if (!empty($branch['sub'])) { $this->_appendNavigation(reset($branch['sub'])); } return $this; } protected function _addListItem() { $this->_initListRedirection(); $dataObj = $this->_getDataObj(); $item = array(); $item['tpl'] = $this->getTemplate('list.tpl'); $item['config'] = $this->getConfig()->toArray(); $categoryId = $dataObj->getCategoryId(); if ($categoryId) { $node = $dataObj->getNode($dataObj->getCategoryTree(), $categoryId); $this->_initPageSeo($node); $categories = (!empty($node['sub'])) ? $node['sub'] : array(); } else { $categories = $dataObj->getCategoryTree(); } $item['list'] = $categories; $this->_addItem($item); return $this; } protected function _addTreeBlock($groupName = null) { $dataObj = $this->_getDataObj(); $productsAlias = Qs_SiteMap::getAliasByItem('ECommerce_Product_'); $nodeIdPrefix = 'node_'; $currentCategoryId = $dataObj->getCategoryId() ?: static::getCategoryId(); $item = [ 'list' => $dataObj->getCategoryTree(), 'finalUrl' => BASE_URL_LANGUAGE . '/' . $productsAlias, 'currentCategoryId' => $currentCategoryId, 'nodeIdPrefix' => $nodeIdPrefix, 'tpl' => $this->getTemplate('tree-list.tpl') ]; $this->_addItem($item, $groupName); $this->_doc->addScript('js/jstree.js'); $this->_doc->addStylesheet('css/thirdpart/jstree/default/style.css'); $this->_doc->addScript('js/app/ECommerce/product/tree.js'); $options = [ 'currentNodeId' => ($currentCategoryId) ? $nodeIdPrefix . $currentCategoryId : null, ]; $this->_doc->addInitObject('app.product.Tree', [$options]); return $this; } public function getMenu() { $menu = $this->_getDataObj()->getCategoryTree(); $this->_prepareMenu($menu); return $menu; } protected function _prepareMenu(array &$menu) { if (!empty($menu)) { foreach ($menu as $key => &$subMenu) { $subMenu['items'] = array('type' => substr(get_class($this), 0, -4)); if (0 == $subMenu['productsCount'] && 0 == $subMenu['subcategoriesProductsCount']) { unset($menu[$key]); } else if (0 == $subMenu['subcategoriesProductsCount']) { $subMenu['sub'] = array(); } else { $this->_prepareMenu($subMenu['sub']); } } } return $this; } public static function getSession() { return new Qs_Session_Namespace('ECommerce_Product_Category'); } public static function saveCategoryId($categoryId, $name = '') { static::getSession()->CategoryId = $categoryId; if (!empty($name)) { static::getSession()->{$name . 'CategoryId'} = $categoryId; } } public static function getCategoryId($name = '') { return static::getSession()->{$name . 'CategoryId'}; } }