Johnny32 Posted March 10, 2014 Share Posted March 10, 2014 Hello Forum, really need help. I looked all over and can not find the info to fix my issue. On my homepage on the left side, all categories and subcategories are sorted by alphabetical order, perfect. When I click on a categorie, the subcategories that show up in the center of the homepage are sorted via ID. Any idea how I can change this, that it will also show alphabetical in the center. Thank you for any help!!! Johnny Link to comment Share on other sites More sharing options...
vekia Posted March 10, 2014 Share Posted March 10, 2014 hello you mean subcategories of parent, currently viewed category? Link to comment Share on other sites More sharing options...
Johnny32 Posted March 10, 2014 Author Share Posted March 10, 2014 Hello, Yes, the subcategories of parent thar are currently viewed in the center of the homepage. They are sorted by ID. They are sorted correclty on the left categorie block. I also just noticed that under the multi navigation block "Home" none of the categories or subcategories are sorted by alphabet when the hidden list pops up. They are sorted by ID. Thanks for any help! Johnny. Link to comment Share on other sites More sharing options...
vekia Posted March 11, 2014 Share Posted March 11, 2014 ok, so the question is: what sort method you want to use there? im asking because this section is totally not related to categories block module. Link to comment Share on other sites More sharing options...
Johnny32 Posted March 11, 2014 Author Share Posted March 11, 2014 Hello, I really need that section to be sorted by name or alphabet as well. Thank you. Link to comment Share on other sites More sharing options...
vekia Posted March 11, 2014 Share Posted March 11, 2014 in Category.php you've got function: public function getSubCategories($id_lang, $active = true) { if (!Validate::isBool($active)) die(Tools::displayError()); $groups = FrontController::getCurrentCustomerGroups(); $sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '='.(int)Group::getCurrent()->id); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT c.*, cl.id_lang, cl.name, cl.description, cl.link_rewrite, cl.meta_title, cl.meta_keywords, cl.meta_description FROM `'._DB_PREFIX_.'category` c '.Shop::addSqlAssociation('category', 'c').' LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').') LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = c.`id_category`) WHERE `id_parent` = '.(int)$this->id.' '.($active ? 'AND `active` = 1' : '').' AND cg.`id_group` '.$sql_groups.' GROUP BY c.`id_category` ORDER BY `level_depth` ASC, category_shop.`position` ASC '); foreach ($result as &$row) { $row['id_image'] = file_exists(_PS_CAT_IMG_DIR_.$row['id_category'].'.jpg') ? (int)$row['id_category'] : Language::getIsoById($id_lang).'-default'; $row['legend'] = 'no picture'; } return $result; } you can see there clause ORDER BY: ORDER BY `level_depth` ASC, category_shop.`position` ASC if you want to sort it by category name instead category_shop.`position` ASC use cl.`name` ASC 1 Link to comment Share on other sites More sharing options...
Johnny32 Posted March 11, 2014 Author Share Posted March 11, 2014 in Category.php you've got function: public function getSubCategories($id_lang, $active = true) { if (!Validate::isBool($active)) die(Tools::displayError()); $groups = FrontController::getCurrentCustomerGroups(); $sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '='.(int)Group::getCurrent()->id); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT c.*, cl.id_lang, cl.name, cl.description, cl.link_rewrite, cl.meta_title, cl.meta_keywords, cl.meta_description FROM `'._DB_PREFIX_.'category` c '.Shop::addSqlAssociation('category', 'c').' LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').') LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = c.`id_category`) WHERE `id_parent` = '.(int)$this->id.' '.($active ? 'AND `active` = 1' : '').' AND cg.`id_group` '.$sql_groups.' GROUP BY c.`id_category` ORDER BY `level_depth` ASC, category_shop.`position` ASC '); foreach ($result as &$row) { $row['id_image'] = file_exists(_PS_CAT_IMG_DIR_.$row['id_category'].'.jpg') ? (int)$row['id_category'] : Language::getIsoById($id_lang).'-default'; $row['legend'] = 'no picture'; } return $result; } you can see there clause ORDER BY: ORDER BY `level_depth` ASC, category_shop.`position` ASC if you want to sort it by category name instead category_shop.`position` ASC use cl.`name` ASC This is how I typed it in and it did not work. ORDER BY `level_depth` ASC, category_shop. cl.`name` ASC This resuted that the sucategories do not appear in the center of the webpage at all nor fixed the hidden drop down categories from the " Home " button. Maybe I did not use the right catergory.php file? Thanks for any help. Link to comment Share on other sites More sharing options...
vekia Posted March 11, 2014 Share Posted March 11, 2014 ORDER BY `level_depth` ASC, category_shop. cl.`name` ASC Link to comment Share on other sites More sharing options...
Johnny32 Posted March 11, 2014 Author Share Posted March 11, 2014 Wow, it fixed the issue with the sorting in the center of the Homepage, thank you very much. The only thing that is still not fixed is the multi navigation block "Home" . When you move the cursor over the " Home " button, the hidden categories and subcategories appear, none of the categories or subcategories that show are sorted by name. They are still sorted by ID. Thanks for any help! Link to comment Share on other sites More sharing options...
vekia Posted March 11, 2014 Share Posted March 11, 2014 in this case everything dependso n module that you use for your menu, it's a default block top menu? Link to comment Share on other sites More sharing options...
Johnny32 Posted March 11, 2014 Author Share Posted March 11, 2014 Hello, Yes, it is still the original default block top menu. Link to comment Share on other sites More sharing options...
vekia Posted March 11, 2014 Share Posted March 11, 2014 in this case you have to modify another sql query in Category.php class you can find code like: public static function getChildren($id_parent, $id_lang, $active = true, $id_shop = false) { if (!Validate::isBool($active)) die(Tools::displayError()); $cache_id = 'Category::getChildren_'.(int)$id_parent.'-'.(int)$id_lang.'-'.(bool)$active.'-'.(int)$id_shop; if (!Cache::isStored($cache_id)) { $query = 'SELECT c.`id_category`, cl.`name`, cl.`link_rewrite`, category_shop.`id_shop` FROM `'._DB_PREFIX_.'category` c LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category`'.Shop::addSqlRestrictionOnLang('cl').') '.Shop::addSqlAssociation('category', 'c').' WHERE `id_lang` = '.(int)$id_lang.' AND c.`id_parent` = '.(int)$id_parent.' '.($active ? 'AND `active` = 1' : '').' GROUP BY c.`id_category` ORDER BY category_shop.`position` ASC'; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); Cache::store($cache_id, $result); } return Cache::retrieve($cache_id); } instead of ORDER BY category_shop.`position` ASC'; use there this code: ORDER BY cl.`name` ASC'; Link to comment Share on other sites More sharing options...
Johnny32 Posted March 11, 2014 Author Share Posted March 11, 2014 You are the best!!! Thanks a million. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now