where('`' . $this->_tableAlias . '`.`enabled` = "y"'); return $this; } /** * @param array $list * @param array $providerOptions * @return App_ECommerce_Product_Category_Search_Obj|Qs_Db_Obj */ protected function _prepareSearchList(array &$list, array $providerOptions) { $categoryObj = new App_ECommerce_Product_Category_Obj(); $tree = $categoryObj->getCategoryTree(); $categories = $this->_flattenTree($tree); $resultList = array(); foreach ($list as $row) { $row = Qs_Array::get($categories, $row['id']); if ($row && $row['productsCount']) { unset($row['sub']); $resultList[] = $row; } } $list = $resultList; parent::_prepareSearchList($list, $providerOptions); $resultTree = array(); foreach ($list as $row) { $chain = $this->_getChain($categories, $row['parentId']); $chain = array_reverse($chain, true); $chain[$row['id']] = $row; $resultTree = Qs_Array::mergeRecursive($resultTree, $this->_getTree($chain)); } $list = $resultTree; return $this; } /** * @param array $tree * @return array */ protected function _flattenTree(array $tree) { $result = array(); foreach ($tree as $key => $node) { $result[$key] = $node; unset($result[$key]['sub']); if ($node['sub']) { $result = Qs_Array::mergeAssoc($result, $this->_flattenTree($node['sub'])); } } return $result; } /** * @param array $categories * @param $parentId * @return array|bool|null */ protected function _getChain(array $categories, $parentId) { $chain = array(); if (array_key_exists($parentId, $categories)) { $chain[$parentId] = array( 'id' => $categories[$parentId]['id'], 'parentId' => $categories[$parentId]['parentId'], 'title' => $categories[$parentId]['title'], ); if (0 != $chain[$parentId]['parentId']) { $chain = Qs_Array::mergeAssoc($chain, $this->_getChain($categories, $chain[$parentId]['parentId'])); } } return $chain; } /** * @param array $chain * @return array */ protected function _getTree(array $chain) { $row = array_shift($chain); $result[$row['id']] = $row; if ($chain) { $result[$row['id']]['sub'] = $this->_getTree($chain); } return $result; } }