Sort alphabetically in product hierarchy

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
tne
Forum Members
Forum Members
Posts: 15
Joined: Wed Oct 23, 2013 6:30 pm

Sort alphabetically in product hierarchy

Post by tne »

Hello!
I need to sort alphabetically product hierarchy. Output pattern is:

Code: Select all

{if !isset($hdepth) && isset($hierarchy_item)}
<h3>Hierarchy Data for {$hierarchy_item.name} ({$hierarchy_item.id})</h3>
{/if}

{if !isset($hdepth)}{assign var='hdepth' value='0'}{/if}
{foreach from=$hierdata key='key' item='item'}
{strip}

<div id="aa" onclick="switchDisplay('{$item.name}')">
 {if isset($active_hierarchy) and $item.id == $active_hierarchy} class="active"{/if}


  {if $item.count gt 0}
    <a href="{$item.url}" class='katalog_link'>{$item.name}</a>
  {else}
    {$item.name}
  {/if}</div>
  

  {if isset($item.children) }

<div class='left_kataloog_otstup' id="{$item.name}" style="width:180px;display:none;font-size: 14px;">

  {include file=$smarty.template hierdata=$item.children hdepth=$hdepth+1}

</div>

  {/if}
  
 
{/strip}
{/foreach}

How to make it displayed in alphabetical order?
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Contact:

Re: Sort alphabetically in product hierarchy

Post by Rolf »

- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
tne
Forum Members
Forum Members
Posts: 15
Joined: Wed Oct 23, 2013 6:30 pm

Re: Sort alphabetically in product hierarchy

Post by tne »

How to apply it to my case?

Code: Select all

{foreach from=$hierdata|sort_array key='key' item='item'}
Tried it, did not work. Help please, I'm not a programmer
tne
Forum Members
Forum Members
Posts: 15
Joined: Wed Oct 23, 2013 6:30 pm

Re: Sort alphabetically in product hierarchy

Post by tne »

Code: Select all

{foreach from=$hierdata|sort_array item='item'}
{$item}
{/foreach}
issues

Code: Select all

Каталог товаров: 

 Array Array Array Array Array Array Array Array Array Array Array Array Array Array Array Array Array Array Array Array Array Array Array Array Array Array Array Array Array Array Array Array Array Array
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Contact:

Re: Sort alphabetically in product hierarchy

Post by Rolf »

ohw uhh wait...
Why not use sort parameters in the Products tag? Read module help for more info.
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
tne
Forum Members
Forum Members
Posts: 15
Joined: Wed Oct 23, 2013 6:30 pm

Re: Sort alphabetically in product hierarchy

Post by tne »

Code: Select all

{Products action="hierarchy" sortorder="asc" pagelimit="10"}
does not work
I have tried 100 variations, but nothing earned
Tell me how to apply your modifier.sort_array.php for this case?
User avatar
paulbaker
Dev Team Member
Dev Team Member
Posts: 1465
Joined: Sat Apr 18, 2009 10:09 pm
Contact:

Re: Sort alphabetically in product hierarchy

Post by paulbaker »

I don't use hierarchy in Products, but I do sort successfully using sortby="[FieldName]". It looks like you are specifying sortorder (up or down) but forgetting sortby?

From Products help:
(optional) sortby="product_name" - Applicable in the summary, categorylist or search actions, this parameter determines the sorting of the output. Possible values are:
item_name
id -- The item id
weight -- The item weight
price -- The item base price
status -- Draft or published
random -- Display in random order on each request
created -- The creation date for this company record
modified -- The modified date for this company record
f:fieldname -- Allows sorting by values of custom fields.

The category list view supports only a few specific sorting options:
id -- The category id.
name -- The category name.

(optional) sortorder="asc" - Specify the order of sorted fields in summary (including after a search) view. Possible values are:
asc -- Ascending order
desc -- Descending order
Post Reply

Return to “The Lounge”