Page 3 of 3

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

Posted: Thu Jul 29, 2010 3:02 pm
by tyman00
The Products module has grown immensely recently due to some very welcome sponsorships. Because the module is so flexible it is very difficult to create an outline for everything that can be done.

I've found that playing with the standard templates will provide great inspiration. Following that learning Smarty by reading the smarty manual and working with {get_template_vars} and {$variable|print_r}  can get you a very long ways.

I've often considered publishing a guide for Products and using some of the other Products Suite modules... just haven't had the time. Since it is in a large growth spurt, I am glad I hadn't... as a majority if it would no longer be valid :)

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

Posted: Thu Jul 29, 2010 3:12 pm
by NikNak
I do understand Tyman.

I just see the methods used by Peciura and wonder how I could have possibly worked them out. They arent based on the {get_template_vars} and print_r are they?  I only got memory errors trying to use print_r on the Products object until I allocated 200 megs of memory in the config.php. 

Methods like $Products->GetProductHierarchyPath for example. Is this a case of digesting  the module code? If so - which files of the module would be a good steer for me to look at? It would be great to know so I can help myself a little more.

Kind regards

Nik

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

Posted: Thu Jul 29, 2010 3:17 pm
by tyman00
Absolutely. Pecuria has a good handle on Products so he knows some of the inner code for writing UDT's.

I'll be honest, I haven't been able to keep up on the current hierarchy settings (will be soon for a a new project though).

So without setting up a test environment I can't say for sure what is available where anymore. I am sure Pecuria will chime in though and let you know how he found all of the info.

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

Posted: Thu Jul 29, 2010 4:43 pm
by Peciura
NikNak: ... wonder how I could have possibly worked them out ...
Try to fork Products module and you will find lost of goodies in Products and CGExtensions :D.

More useful thing about all modules derived from CGExtensions, they all have {$actionid} available in templates AND there are Objects named as modules (Products, Cart, ...) so you can use them to access public module methods (they are listed on "/modules/Module_name/Module_name.module.php"). The rest of modules have variable {$mod} so each time different module is called that variable is overwritten. To avoid that, you have to save module object to unique variable at the top of template.
Knowing this stuff you can get everything from module (not only {$mod->Lang('something')}), also build own action links and forms. E.G. this looks easy

Code: Select all

{$input_search_proddesc}
but this  one is simply godsend when you understand it

Code: Select all

<input type="text"  name="{$actionid}cd_proddesc" size="25" maxlength="255" title="{$mod->Lang('search_description')}"/>
Regarding documentation, writing   phpDocumentor friendly code and basic info on help page is enough. Writing everything to help page is inefficient and time-consuming. Wiki can be improved by people like you and me. And last thing, you did not hesitate to test my suggestions ( was it 4 times ? ) so finally you have a solution that works not only for me but also for you.

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

Posted: Sat Sep 25, 2010 3:13 pm
by mvandiermen
Peciura wrote:
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 v2.8.7)
{Products hierarchyid=$hierarchy_item.id}
I tried the above code (just pasted it into my sample Hierarchy Report Template)

and this was displayed on the Hierarchy index:
"
Hierarchy Data for ()
Child Nodes
()


()


Products matching this location in hierarchy
"


Don't know what I am missing

THis is my current sample Hierarchy Report Template

Code: Select all

{* hierarchy report template *}
{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}
{*
 // 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
*}
<ul class="products_hierarchy_level{$hdepth}">
{foreach from=$hierdata key='key' item='item'}
{strip}
  <li {if isset($active_hierarchy) and $item.id == $active_hierarchy} class="active"{/if}>
  {if $item.count gt 0}
     <a href="{$item.url}">{$item.name} ({$item.count})</a>
  {else}
     {$item.name} ({$item.count})
  {/if}
  
  {if isset($item.children) }
    {* there are children call this template again *}
    {include file=$smarty.template hierdata=$item.children hdepth=$hdepth+1}
  {/if}
  
  </li>
{/strip}



{/foreach}
</ul>

I am looking for a way to put the hierarchy images field onto the Hierarchy Report Template > Sample. Products v2.8.7

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

Posted: Sat Sep 25, 2010 4:28 pm
by mvandiermen
I figured it out myself
/uploads/Products/{$item.image}
:)

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

Posted: Sat Sep 25, 2010 4:32 pm
by mvandiermen
or better is /uploads/Products/thumb_{$item.image}

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

Posted: Sat Sep 25, 2010 4:40 pm
by mvandiermen
woops I mean
uploads/Products/hierarchy/thumb_{$item.image}

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

Posted: Fri Oct 08, 2010 7:22 pm
by FX_Odessa
OOOhhhh VERY BIG 10X

after update - a have a brain storm ) ) ) )

my template @ http://atillaglass.com/index.php?page=katalog

Code: Select all

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

<div class="hie_row">
{if $item.count gt 0}
	<div class="hie_pic"><a href="{$item.url}"><img src="{$hierarchy_image_location}/{$item.image}" alt="{$item.name}" class="hie_img"></a></div>
	<div class="hie_name"><a href="{$item.url}">{$item.name} </a></div>
{else}
	<div class="hie_pic"><img src="{$hierarchy_image_location}/{$item.image}" alt="{$item.name}" class="hie_img"></div>
	<div class="hie_name">{$item.name}</div>{/if}
	<div class="hie_description">{$item.description}</div>
<div class="cl"></div>
</div>

{/strip}
{/foreach}