_filter, 'industryType')) { $join = 'pc2it.categoryId = ProductCategory.id AND pc2it.industryTypeId = ' . $industryTypeId; $select->join($this->_getPair('ProductCategory2IndustryType', 'pc2it'), $join, null); } if ($typeId = (int) Qs_Array::get($this->_filter, 'categoryType')) { $select->where('`' . $this->_tableAlias . '`.`typeId` = ?', $typeId, Qs_Db::INT_TYPE); } return parent::_filter($select); } public static function getCategoryIdByAlias($alias) { if (!is_array($alias)) { $alias = explode('/', $alias); } $aliasCount = count($alias); if ($aliasCount > 1) { if ('page' == $alias[$aliasCount - 2] && is_numeric($alias[$aliasCount - 1])) { $alias = array_slice($alias, 0, -2); } } $db = Qs_Db::getInstance(); $tableShortName = 'ProductCategory'; $alias = array_reverse($alias); $iteration = 0; $select = $db->select(); $select->from(array('i' . $iteration => Qs_Db::getTableName($tableShortName)), 'id'); $select->where('`i' . $iteration . '`.`alias` = ?', (string) array_shift($alias)); while (!empty($alias)) { $iteration++; $select->join( array('i' . $iteration => Qs_Db::getTableName($tableShortName)), '`i' . $iteration . '`.`id` = `i' . ($iteration - 1) . '`.`parentId`', '' ); $select->where('`i' . $iteration . '`.`alias` = ?', (string) array_shift($alias)); } return $db->fetchOne($select); } protected function _addDependenciesFromDb(array &$data) { $this->_addColorsDependency($data); $this->_addSizesDependency($data); $this->_addShapesDependency($data); return $this; } protected function _addColorsDependency(array &$data) { $select = $this->_db->select(); $where = 'color.id = relations.signColorId AND category.id = relations.categoryId AND category.id = ' . (int) $this->getPrimaryKey(); $select->from($this->_getPair('SignColor', 'color'), array('id', 'title', 'titleColor', 'bgColor')) ->join($this->_getPair($this->_tableAlias, 'category'), '1', null) ->join($this->_getPair($this->_tableAlias . '2SignColor', 'relations'), $where, null) ->order('color.sorter'); $data['colors'] = Qs_Array::group($select->query()->fetchAll(), array('id')); return $this; } protected function _addSizesDependency(array &$data) { $select = $this->_db->select(); $select->from($this->_getPair('SignSize', 'size'), array('id', 'title')); $select->where('size.productCategoryId = ?', $this->getPrimaryKey()); $select->order('size.sorter'); $data['sizes'] = Qs_Array::group($select->query()->fetchAll(), array('id')); return $this; } protected function _addShapesDependency(array &$data) { $select = $this->_db->select(); $where = 'shape.id = relations.signShapeId AND category.id = relations.categoryId AND category.id = ' . (int) $this->getPrimaryKey(); $select->from($this->_getPair('SignShape', 'shape'), array('id', 'title', 'image')) ->join($this->_getPair($this->_tableAlias, 'category'), '1', null) ->join($this->_getPair($this->_tableAlias . '2SignShape', 'relations'), $where, null) ->order('shape.sorter'); $data['shapes'] = Qs_Array::group($select->query()->fetchAll(), array('id')); return $this; } public function setCategoryIdByAlias($alias) { $categoryId = static::getCategoryIdByAlias($alias); $this->setCategoryId($categoryId); return $this; } public function setCategoryId($categoryId) { $this->_categoryId = $categoryId; return $this; } public function getCategoryId() { return $this->_categoryId; } public function getListSelect() { if (null === $this->_select) { parent::getListSelect(); $this->_select->where('`' . $this->_tableAlias . '`.`enabled` = "y"'); } return $this->_select; } public function getCategoriesForIndustryType() { $select = $this->getListSelect(); $select->reset(Zend_Db_Select::ORDER)->order(array('title', 'parentId')); return $this->_db->fetchAll($select); } public function getCategoryListForIndustryType() { $list = $this->getCategoriesForIndustryType(); $productsPageAlias = Qs_SiteMap::findFirst(null, ['type' => 'ECommerce_Product_'], null, 'alias'); foreach($list as &$item) { $item['url'] = Qs_Constant::get('BASE_URL') . '/' . $productsPageAlias . '/' . $item['alias']; } return $list; } }