Products 2.8 > how to use hierarchy and categorylist ?

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Peciura

Re: Products 2.8 > how to use hierarchy and categorylist ?

Post by Peciura »

How display image and description?
Products 2.8.2

Code: Select all

{* hierarchy report template *}
<h3>Hierarchy Data for {$hierarchy_item.name} ({$hierarchy_item.id})</h3>
{if isset($upurl)}
	<p><a href='{$upurl}' title='{$mod->Lang('parent')}'>{$mod->Lang('parent')}</a></p>
{/if}
{assign var='prodmod' value=$mod}

{if isset($parent)}
	<h4>This Node</h4>
	Name: {$parent.name}
	Description: {$parent.description}<br/>
{/if}

<h4>Child Nodes</h4>
{if isset($hierdata) && count($hierdata)}
	{foreach from=$hierdata item='node'}
		<h5>
			{if isset($node.$datakey.url)}
				<a href='{$node.$datakey.url}' title='{$node.$datakey.name}'>{$node.$datakey.name}</a>
			{else}
				{$node.$datakey.name}
			{/if}
		</h5>
		{if !empty($node.$datakey.image)}
			{capture assign='image'}{$hierarchy_image_location}/{$node.$datakey.image}{/capture}
			{capture assign='name'}{$node.$datakey.name}{/capture}
			{if !empty($node.$datakey.thumbnail)}
				{capture assign='thumb'}{$hierarchy_image_location}/{$node.$datakey.thumbnail}{/capture}
				<a href="{$image}" class="fancybox" rel="nofollow"><img src='{$thumb}' alt='{$name}'/></a>
			{else}
				<img src="{$image}" alt="{$name}"/>
			{/if}
		{/if} ({$node.$datakey.count})
		{if !empty($node.$datakey.description)}
			<p>Description: {$node.$datakey.description}</p>
		{/if}
		<br/><br/>
	{/foreach}
{/if}

<h5>Products matching this location in hierarchy</h5>
{Products hierarchyid=$hierarchy_item.id}
Last edited by Peciura on Fri Jun 11, 2010 5:10 pm, edited 1 time in total.
maranc
Forum Members
Forum Members
Posts: 249
Joined: Tue May 04, 2010 5:04 pm

Re: Products 2.8 > how to use hierarchy and categorylist ?

Post by maranc »

Thanks a lot Peciura, I tested your template and hier are results:
- I see parent, descritption of parent and associated image
- When I click on parent I still dont see childs (I have some products in subhierarchy - but I can't display it)
- on parent count shows always '0'

Some better (description and image are showing), but hierarchy still not working.

BTW - I checked my database tabels and saw somthing like this:
1. cms_module_products_hierarchy - tabel, where is structure hierarchy
2. cms_module_products_prodtohier - tabel, witch was created on update module. Hier are 2 colums:
            product_id    hierarchy_id
1 10
2 10
5 6
6 8
7 10
8 12

Maybe hier is a problem? I'm not expert....

Marek A.
Peciura

Re: Products 2.8 > how to use hierarchy and categorylist ?

Post by Peciura »

ATM hierarchy action does not count products recursively.

This template should output hierarchy tree. To make it menu like you need to add  proper CSS or/and JavaScript.
{* hierarchy report template *}
{if !isset($hdepth)}
Hierarchy Data for {$hierarchy_item.name} ({$hierarchy_item.id})
{/if}

{if !isset($hdepth)}{assign var='hdepth' value='0'}{/if}
{*
// create a nested set of unordered lists
// if the active_hierarchy smarty variable exists
// and matches the current hierarchy id
// the active class will be given
// to the ul.  You may want to modify your summary template
// to set this variable
*}

{foreach from=$hierdata key='key' item='item'}
{strip}
{if isset($item.$datakey)}

{if $item.$datakey.count gt 0} {*hier title*}
{$item.$datakey.name} ({$item.$datakey.count})
{else}
{$item.$datakey.name} ({$item.$datakey.count})
{/if}
{if !empty($item.$datakey.thumbnail)} {*image*}
{capture assign='thumb'}{$hierarchy_image_location}/{$item.$datakey.thumbnail}{/capture}
{capture assign='image'}{$hierarchy_image_location}/{$item.$datakey.image}{/capture}

{else}

{/if}
{if !empty($item.$datakey.description)} {*description*}
Description: {$item.$datakey.description}
{/if}

{/if}
{if $key|is_numeric}
{* it's a child -- call this template again with the node *} {*this is recursive part*}
{include file=$smarty.template hierdata=$item hdepth=$hdepth+1}
{/if}

{/strip}
{/foreach}


{*Products matching this location in hierarchy*}
{*Products hierarchyid=$hierarchy_item.id*} {*not used at the moment*}
eleventh
Forum Members
Forum Members
Posts: 10
Joined: Wed Jun 30, 2010 12:46 pm

Re: Products 2.8 > how to use hierarchy and categorylist ?

Post by eleventh »

How to activate "active_hierarchy" variable?

I want to set on hierarchy tree active link.

Thanks
tyman00
Power Poster
Power Poster
Posts: 906
Joined: Tue Oct 24, 2006 5:59 pm

Re: Products 2.8 > how to use hierarchy and categorylist ?

Post by tyman00 »

eleventh wrote: How to activate "active_hierarchy" variable?

I want to set on hierarchy tree active link.

Thanks
I think active_hierarchy is set by the module. I haven't had much of a chance to play with the new hierarchy setup, but that seems most logical to me.
If all else fails, use a bigger hammer.
M@rtijn wrote: This is a community. This means that we work together and have the same goal (a beautiful CMS), not that we try to put people down and make their (voluntary) job as difficult as can be.
Peciura

Re: Products 2.8 > how to use hierarchy and categorylist ?

Post by Peciura »

What is 'active' hierarchy ?

Code: Select all

{assign var='active_hierarchy' value=53}
Would "activate" hierarchy with id = 53. Normally it depends on hierarchy-link pressed by visitor. It is set by module each time page reloads.

Or do you mean some JavaScript that expands and collapses hierarchy level without reloading page ?
User avatar
NikNak
Forum Members
Forum Members
Posts: 183
Joined: Fri Oct 02, 2009 2:28 pm

Re: Products 2.8 > how to use hierarchy and categorylist ?

Post by NikNak »

Hi Peciura
In the Hierarchy template it mentions this:
// create a nested set of unordered lists
// if the active_hierarchy smarty variable exists
// and matches the current hierarchy id
// the active class will be given
// to the ul.  You may want to modify your summary template
// to set this variable

My question is - how do I get the data to set this variable in the summary template?

This variable doesn't seem to be set by the module (as far as I can tell), so if you have to set it yourself in a template, where do you get the correct id from?

Kind regards
Nik
Last edited by NikNak on Wed Jul 28, 2010 1:08 pm, edited 1 time in total.
Peciura

Re: Products 2.8 > how to use hierarchy and categorylist ?

Post by Peciura »

I assume you have set

Code: Select all

$config['process_whole_template'] = false;
and {Products action='hierarchy'} is in page template ( probably on one or another side).
If that is true after you press any hierarchy you will get a list of product in {content} area. Variables created in {content} area (Products summary action) are available in page template.
So we have to find out what hierarchy products belongs to and save that value to variable. But i prefer to know not only hierarchy product is assigned to but also all parent hierarchy steps. So i named variable "active_hierarchy_path". Last member stores id of hierarchy product is explicitly assigned to ( class='current' ), the rest - parent hierarchies ( class='active' ).

This is fragment of summary template
...
{assign var='active_hierarchy_path' value=$Products->GetProductHierarchyPath($items[0]->id)}
{foreach from=$items item=entry}
...

Here is fragment of hierarchy template
{if $item.count gt 0}
{$item.name} ({$item.count})
{else}
{$item.name} ({$item.count})
{/if}

{else}
...
Last edited by Peciura on Thu Jul 29, 2010 4:02 pm, edited 1 time in total.
User avatar
NikNak
Forum Members
Forum Members
Posts: 183
Joined: Fri Oct 02, 2009 2:28 pm

Re: Products 2.8 > how to use hierarchy and categorylist ?

Post by NikNak »

Hi Peciura
This sounds great but I cannot get these variables.
Process whole template is false. My left column is {Products action="hierarchy"}. Im running cmsms 1.8.1 and Products 2.8.3 . I have entered your code in the summary template.

Using {get_template_vars} I can see active_hierarchy_path is not set
$items->hierarchy_id is also unset and using {$items|@print_r} I cannot see a hierarchy_id in there at all.

In the var dump
Products = Object
summary =
I can see no action variable

???  I'm really confused now.

Kind regards
Nik
Peciura

Re: Products 2.8 > how to use hierarchy and categorylist ?

Post by Peciura »

Just fixed previous post (summary fragment). I assume array {$items} contains products in summary mode. If it does not work post your summary template
User avatar
NikNak
Forum Members
Forum Members
Posts: 183
Joined: Fri Oct 02, 2009 2:28 pm

Re: Products 2.8 > how to use hierarchy and categorylist ?

Post by NikNak »

Hi again - well nothing changed, so I made a complete fresh install of 1.8.1 with the latest Products module and the default templates.
$items[0]->hierarchy_id does not exist in the array
$items[0]->id does

Code: Select all

Array ( [0] => stdClass Object ( [id] => 3 [product_name] => Item 3 [details] => [price] => 0 [create_date] => 2010-07-29 10:18:44 [modified_date] => 2010-07-29 10:18:44 [taxable] => 1 [status] => published [weight] => 0 [sku] => [alias] => Item-3 [detail_url] => http://##/index.php?mact=Products,cntnt01,details,0&cntnt01parent=1&cntnt01hierarchyid=4&cntnt01returnid=15&cntnt01productid=3&cntnt01returnid=15 [product_name_link] => Item 3 [file_location] => http://##/uploads/Products/product_3 [fields] => Array ( ) ) [1] => stdClass Object ( [id] => 4 [product_name] => Item 4 [details] => [price] => 0 [create_date] => 2010-07-29 10:18:57 [modified_date] => 2010-07-29 10:18:57 [taxable] => 1 [status] => published [weight] => 0 [sku] => [alias] => Item-4 [detail_url] => http://##/index.php?mact=Products,cntnt01,details,0&cntnt01parent=1&cntnt01hierarchyid=4&cntnt01returnid=15&cntnt01productid=4&cntnt01returnid=15 [product_name_link] => Item 4 [file_location] => http://##/uploads/Products/product_4 [fields] => Array ( ) ) )
However - $Products->GetHierarchyPath($items[0]->id) gives no result.
nor does $Products->GetHierarchyPath(3)

Out of curiosity - do you know if the parent parameter does anything, or are you expected to change the hierarchy template to implement this. {Products action="hierarchy" parent="1"} as the entire hierarchy is always shown whatever the parent is set to.

Kind regards

Nik
Peciura

Re: Products 2.8 > how to use hierarchy and categorylist ?

Post by Peciura »

NikNak : check it now.

EDIT: You were right, it my mod to have hierarchy_id for each product in summary template.
Sorry  ::)
Last edited by Peciura on Thu Jul 29, 2010 10:22 am, edited 1 time in total.
User avatar
NikNak
Forum Members
Forum Members
Posts: 183
Joined: Fri Oct 02, 2009 2:28 pm

Re: Products 2.8 > how to use hierarchy and categorylist ?

Post by NikNak »

Now it gets a result - great stuff. Thanks so much. I just don't know how users like me could ever work this out. I have spent a day on this!

But do you have any idea about the hierarchy template showing the entire hierarchy whatever parameter is add using parent="1".  With {Products action="hierarchy" parent="1"} I get:

Hierarchy Data for Things A (1)
Things A (0)
Subthings 1 (2)
Subthings 2 (2)
Things B (0)
Subthings 1 (1)
Subthings 2 (1)
Peciura

Re: Products 2.8 > how to use hierarchy and categorylist ?

Post by Peciura »

I believe usage of  parameter "parent" should be fixed some time, because it is not working as expected and is interfering with module parameter "hierarchyid".
User avatar
NikNak
Forum Members
Forum Members
Posts: 183
Joined: Fri Oct 02, 2009 2:28 pm

Re: Products 2.8 > how to use hierarchy and categorylist ?

Post by NikNak »

Thanks again Peciura - I'm very grateful for your time

It is a shame there is not more documentation for this great module, as the things I have tried to do (I would have thought) were fairly standard, but have proved frustratingly difficult and time consuming.

PS - In the hierarchy template the code should have been 
{if isset($active_hierarchy_path) and $item.node.id|in_array:$active_hierarchy_path}

Kind regards
Nik
Post Reply

Return to “Modules/Add-Ons”