'list']; 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->_do404(); } } } 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 = ['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 = []; $item['tpl'] = $this->getTemplate('list.tpl'); $item['config'] = $this->getConfig()->toArray(); $categoryId = $dataObj->getCategoryId(); if ($categoryId) { $node = $dataObj->getNode($dataObj->getCategoryTree(), $categoryId); if ($node) { $this->_initPageSeo($node); } $categories = (!empty($node['sub'])) ? $node['sub'] : []; } else { $categories = $dataObj->getCategoryTree(); } $item['list'] = $categories; $this->_addItem($item); return $this; } protected function getCategoryTree() { $tree = $this->_getDataObj()->getCategoryTree(); Qs_Array::treeWalk($tree, function (&$item) { if (!$item['subcategoriesProductsCount']) { $item['sub'] = []; } return $item['productsCount'] || $item['subcategoriesProductsCount']; }); return $tree; } protected function _addTreeBlock($groupName = null) { $categoryTree = $this->_getDataObj()->getCategoryTree(); $productsAlias = Qs_SiteMap::getAliasByItem('ECommerce_Product_'); $parent = null; $item = [ 'tree' => $this->getCategoryTree(), 'list' => $categoryTree, 'link' => ['product' => $productsAlias], 'finalUrl' => BASE_URL_LANGUAGE . '/' . $productsAlias, 'currentCategoryId' => $this->_getDataObj()->getCategoryId() ? $this->_getDataObj()->getCategoryId() : static::getCategoryId(), 'tpl' => $this->getTemplate('tree-list.tpl'), ]; $this->_addItem($item, $groupName); $this->_doc->addCriticalStylesheet('css/modules/sideBlock.css'); $this->_doc->addCriticalStylesheet('css/thirdpart/jquery.treeview.css'); $this->_doc->addScript('js/jquery.treeview.js'); $id = 'tree'; $options = ['collapsed' => false, 'animated' => 'medium', 'control' => '#sidetreecontrol', 'persist' => 'location']; $this->_doc->addInitObject("$('#{$id}').treeview", [$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'] = ['type' => substr(get_class($this), 0, -4)]; if (0 == $subMenu['productsCount'] && 0 == $subMenu['subcategoriesProductsCount']) { unset($menu[$key]); } else if (0 == $subMenu['subcategoriesProductsCount']) { $subMenu['sub'] = []; } 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'}; } }