Jump to content

Sorting sub-categories in category.tpl so that output is alphabetical


Torbz

Recommended Posts

Hi folks,

 

I realise there's probably thousands of questions on here unanswered, and hope this is not one of those in the making....

 

Have a look at:

http://bluecedaronline.co.uk/index.php?id_category=5&controller=category

 

I need those sub-categories to be sorted alphabetically, rather than respecting the back office ORDER.

v.1.5.5

 

I know it involves this section of category.tpl:

	{if isset($subcategories)}
		<!-- Subcategories -->
		<div id="subcategories">
			<h3>{l s='Subcategories'}</h3>
			<ul class="inline_list">
            
			{foreach from=$subcategories item=subcategory}
            
				<li>
					<a href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'htmlall':'UTF-8'}" title="{$subcategory.name|escape:'htmlall':'UTF-8'}">
						{if $subcategory.id_image}
							<img src="{$link->getCatImageLink($subcategory.link_rewrite, $subcategory.id_image, 'medium')}" alt="" width="{$mediumSize.width}" height="{$mediumSize.height}" />
						{else}
							<img src="{$img_cat_dir}default-medium.jpg" alt="" width="{$mediumSize.width}" height="{$mediumSize.height}" />
						{/if}
					</a><br />
					<a href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'htmlall':'UTF-8'}">{$subcategory.name|escape:'htmlall':'UTF-8'}</a>
				</li>
			{/foreach}
			</ul>
			<br class="clear"/>
		</div>
		{/if}

But I don't know how the 'array' of $link that gets spat out can be re-organised A > Z

 

There many topics on this subject, but none directly address what I'm trying to achieve and there's not a lot of similar experience out there.

 

I'd appreciate any pointers or help to sort this List.

 

Torbz

:)

Edited by Torbz (see edit history)
Link to comment
Share on other sites

  • 3 months later...
  • 1 month later...
  • 1 month later...
  • 4 months later...
  • 3 weeks later...

This helped a lot. I only wanted to reverse the subcategory links so I did something a tiny bit different. 

 

I've got v1.4.10 and I changed row 473 from this: 

ORDER BY `level_depth` ASC, c.`position` ASC');

To this:

ORDER BY `level_depth` ASC, c.`position` DESC');
Link to comment
Share on other sites

  • 1 year later...

 

Solution:

In the /classes/Category.php on the line 532 (Prestashop 1.5.1.0) on the public function getSubCategories

 

Change this: ORDER BY `level_depth` ASC, category_shop.`position` ASC

 
For: ORDER BY cl.name ASC, category_shop.`position` ASC

 

 

Excelente respuesta! Casi la tenía, pero no sabía donde buscar.

Link to comment
Share on other sites

  • 1 month later...
  • 10 months later...
 $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('

SELECT *

FROM `'._DB_PREFIX_.'category` c

'.Shop::addSqlAssociation('category', 'c').'

LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON c.`id_category` = cl.`id_category`'.Shop::addSqlRestrictionOnLang('cl').'

WHERE 1 '.$sql_filter.' '.($id_lang ? 'AND `id_lang` = '.(int)$id_lang : '').'

'.($active ? 'AND `active` = 1' : '').'

'.(!$id_lang ? 'GROUP BY c.id_category' : '').'

'.($sql_sort != '' ? $sql_sort : 'ORDER BY c.`level_depth` ASC, category_shop.`position` ASC').'

'.($sql_limit != '' ? $sql_limit : '')

 

If i understand it correctly, this set up should sort category by their internal number, right? But in my shop it sorting it alphabeticly. Any idea why?

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...