Whispar1 Posted May 9, 2014 Share Posted May 9, 2014 For some reason, my sub categories are NOT in the order I have placed them in the BO For example - our Lighting Category: http://www.whispardesign.com/10-home-lighting Here is my order in the back office (which is how I want it to display on the front end: Any thoughts? Link to comment Share on other sites More sharing options...
vekia Posted May 10, 2014 Share Posted May 10, 2014 in this case everything depends on module that you use. it's necessary to analyse the code of this addon first check what method it uses in hookLeftColumn function in default module you can find function $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite FROM `'._DB_PREFIX_.'category` c INNER JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = '.(int)$this->context->language->id.Shop::addSqlRestrictionOnLang('cl').') INNER JOIN `'._DB_PREFIX_.'category_shop` cs ON (cs.`id_category` = c.`id_category` AND cs.`id_shop` = '.(int)$this->context->shop->id.') WHERE (c.`active` = 1 OR c.`id_category` = '.(int)Configuration::get('PS_HOME_CATEGORY').') AND c.`id_category` != '.(int)Configuration::get('PS_ROOT_CATEGORY').' '.((int)$maxdepth != 0 ? ' AND `level_depth` <= '.(int)$maxdepth : '').' '.$range.' AND c.id_category IN ( SELECT id_category FROM `'._DB_PREFIX_.'category_group` WHERE `id_group` IN ('.pSQL(implode(', ', Customer::getGroupsStatic((int)$this->context->customer->id))).') ) ORDER BY `level_depth` ASC, '.(Configuration::get('BLOCK_CATEG_SORT') ? 'cl.`name`' : 'cs.`position`').' '.(Configuration::get('BLOCK_CATEG_SORT_WAY') ? 'DESC' : 'ASC')); it's neccessary to change ORDER BY clause Link to comment Share on other sites More sharing options...
Whispar1 Posted May 10, 2014 Author Share Posted May 10, 2014 Thanks Vekia. This is my current code: I guess I do not see what change I need to make to make the display order of sub-categories the same order as both the back office and the navigation menu at the top. (BTW, the top navigation sub-categories matches the order of sub categories in the back office - only the display order of subcategories is shown in random order) public function getSubCategories($id_lang, $active = true) { if (!Validate::isBool($active)) die(Tools::displayError()); $groups = FrontController::getCurrentCustomerGroups(); $sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1'); $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 '); Link to comment Share on other sites More sharing options...
vekia Posted May 10, 2014 Share Posted May 10, 2014 everything depends how you want to sort them you have to change this line: ORDER BY `level_depth` ASC, category_shop.`position` ASC for example ORDER BY `level_depth` ASC, cl.`name` ASC 1 Link to comment Share on other sites More sharing options...
Whispar1 Posted May 10, 2014 Author Share Posted May 10, 2014 Thanks again Vekia. I would like them sorted exactly how they are in the BO photo (which is the same sort order for the top navigation menu. Link to comment Share on other sites More sharing options...
vekia Posted May 11, 2014 Share Posted May 11, 2014 your code sort them with position :/ ORDER BY `level_depth` ASC, category_shop.`position` ASC can you show contents of your tpl file? Link to comment Share on other sites More sharing options...
Whispar1 Posted May 11, 2014 Author Share Posted May 11, 2014 Sure - here is category.tpl {include file="$tpl_dir./breadcrumb.tpl"} {include file="$tpl_dir./errors.tpl"} <div class="main row"> <!-- right content start --> <div class="col-main span9"> <!-- cart baner --> <div class="category-description std"> <div class="row"> {$sccop.trendy_category_page_markup|html_entity_decode} </div> </div> <!-- end the cart baner --> {if isset($category)} {if $category->id AND $category->active} <!-- <div class="resumecat category-product-count"> {include file="$tpl_dir./category-count.tpl"} </div> --> {if $scenes || $category->description || $category->id_image} <div class="content_scene_cat"> {if $scenes} <!-- Scenes --> {include file="$tpl_dir./scenes.tpl" scenes=$scenes} {else} <!-- Category image --> {if $category->id_image} <div class="align_center"> <img src="{$link->getCatImageLink($category->link_rewrite, $category->id_image, 'category_default')}" alt="{$category->name|escape:'htmlall':'UTF-8'}" title="{$category->name|escape:'htmlall':'UTF-8'}" id="categoryImage" width="{$categorySize.width}" height="{$categorySize.height}" /> </div> {/if} {/if} {if $category->description} <p></p> <div class="cat_desc"><!-- swap p with div to allow tinymce --> {if strlen($category->description) > 800} <div id="category_description_short">{$category->description|truncate:800}</div><!-- swap p with div to allow tinymce --> <div id="category_description_full" style="display:none">{$category->description}</div><!-- swap p with div to allow tinymce --> <a href="#" onclick="$('#category_description_short').hide(); $('#category_description_full').show(); $(this).hide(); return false;" class="lnk_more">{l s='More'}</a> {else} <div>{$category->description}</div><!-- swap p with div to allow tinymce --> {/if} </div> {/if} </div> {/if} {if isset($subcategories)} <!-- Subcategories --> <div id="subcategories"> <h3>{l s='Subcategories'}</h3> <ul class="inline_list"> {foreach from=$subcategories item=subcategory} <li class="clearfix"> <a href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'htmlall':'UTF-8'}" title="{$subcategory.name|escape:'htmlall':'UTF-8'}" class="img"> {if $subcategory.id_image} <img src="{$link->getCatImageLink($subcategory.link_rewrite, $subcategory.id_image, 'medium_default')}" alt="{$subcategory.name|escape:'htmlall':'UTF-8'}" width="{$mediumSize.width}" height="{$mediumSize.height}" /> {else} <img src="{$img_cat_dir}default-medium_default.jpg" alt="{$subcategory.name|escape:'htmlall':'UTF-8'}" width="{$mediumSize.width}" height="{$mediumSize.height}" /> {/if} </a> <!--add h2 for SEO--> <h2><a href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'htmlall':'UTF-8'}" class="cat_name">{$subcategory.name|escape:'htmlall':'UTF-8'}</a></h2> <!-- {if $subcategory.description} <p class="cat_desc">{$subcategory.description}</p> {/if}--> {if $subcategory.short_description} <p class="cat_desc">{$subcategory.short_description}</p><!-- swap p with div to allow tinymce --> {elseif $subcategory.description} <p class="cat_desc">{$subcategory.description}</p> {/if} </li> {/foreach} </ul> <br class="clear"/> </div> {/if} <div class="page-title category-title"> {if $products} <a href="{$link->getPageLink('products-comparison')}" title="" class="compaate_button">{l s='Compare'}</a> {/if} <h2> {*change from h1 *} {strip} {$category->name|escape:'htmlall':'UTF-8'} {if isset($categoryNameComplement)} {$categoryNameComplement|escape:'htmlall':'UTF-8'} {/if} {/strip} </h2> </div> {if $products} <div class="toolbar"> <div class="tb"> <div class="sorter"> <p class="view-mode"> <strong title="Grid" class="grid grid-active"> </strong> <a href="#" title="List" class="list"> </a> </p> {include file="./product-sort.tpl"} </div> <div class="pager hidden-phone"> {include file="./nbr-product-page.tpl"} </div> </div> </div> {include file="./product-list.tpl" products=$products} <div class="toolbar-bottom"> <div class="toolbar"> <div class="tb"> <div class="sorter"> <p class="view-mode"> <strong title="Grid" class="grid grid-active"> </strong> <a href="#" title="List" class="list"> </a> </p> {include file="./product-sort.tpl"} </div> <div class="pager hidden-phone"> {include file="./nbr-product-page.tpl"} </div> </div> </div> </div> {include file="./pagination.tpl"} {/if} {elseif $category->id} <p class="warning">{l s='This category is currently unavailable.'}</p> {/if} {/if} <!-- end the span9 --> </div> <!-- left content end --> <!-- start col-left sidebar span3 --> <div class="col-left sidebar span3"> {$HOOK_LEFT_COLUMN} </div> <!-- end the left sidebar --> <!-- end the main row --> </div> Link to comment Share on other sites More sharing options...
vekia Posted May 11, 2014 Share Posted May 11, 2014 omg i probably missed something. youre talking about: subcategories in blockcategory (everthing i wrote was based on this) or about subcategories displayed inside category page? Link to comment Share on other sites More sharing options...
Whispar1 Posted May 11, 2014 Author Share Posted May 11, 2014 (edited) or about subcategories displayed inside category page? LOL no worries Vekia - Yes, if you look at this link... http://www.whispardesign.com/10-home-lighting you will see that the order of the subcategories is random, not as defined in navigation, block category, and BO Edited May 11, 2014 by Whispar1 (see edit history) Link to comment Share on other sites More sharing options...
Whispar1 Posted May 12, 2014 Author Share Posted May 12, 2014 Vekia, Is there anything else you need me to post or do you have another idea? Link to comment Share on other sites More sharing options...
vekia Posted May 13, 2014 Share Posted May 13, 2014 you can try to change category_shop.`position` ASC to c.`position` ASC but in fact, category positions are stored in ps_category_shop table, this is why it's weird that it doesnt work for you. prestashop stores information about position also in ps_category table, so this is why i suggested to use c.position maybe this is the key to your problem Link to comment Share on other sites More sharing options...
Whispar1 Posted May 13, 2014 Author Share Posted May 13, 2014 are you saying to try and change this in category.php? If so, There are three instances of that string...change all of them do you think? category_shop.`position` ASC Link to comment Share on other sites More sharing options...
Whispar1 Posted May 21, 2014 Author Share Posted May 21, 2014 you can try to change category_shop.`position` ASC to c.`position` ASC but in fact, category positions are stored in ps_category_shop table, this is why it's weird that it doesnt work for you. prestashop stores information about position also in ps_category table, so this is why i suggested to use c.position maybe this is the key to your problem I changed all three instances in category.php to what you suggested but nothing changed (and nothing broke so this is good too) 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