I have been playing around with the ecommerce suite. Firstly, it is fantastic work by CG, considering that there are other products out there that charge a pretty penny for what he delivered here free of charge. Anyway, on to the question.
PS: I HAVE MADE PROGRESS - PLEASE SEE POST AFTER THIS
I want to display products by hierarchy, but only one level at a time. So if someone selects products i want to display the top level items. But when clicking on the top level items, i don't want to direct the user to the summary page, but instead to the level below that in the hierarchy. When it is a product on the lowest level, i want to display a link to the product summary.
I understand the logic, but i am not sure how to implement it. Logically i want to say:
If you click this link
Code: Select all
{if $item.count gt 0}
<a href="{$item.url}">{$item.name} (IN STOCK: {$item.count})</a>
{else}
<a href="{$item.url}">{$item.name} (OUT OF STOCK)</a>
{/if}
Code: Select all
{if isset($item.children) }
{* there are children call this template again *}
{include file=$smarty.template hierdata=$item.children hdepth=$hdepth+1}
{/if}
To summarise:
1.) How do i change the anchors to link to next hierarchy level instead of to products? (since there are none for higher hierarchical levels) <a href="{$item.url}">...
2.) Can i do a check to see if there are no more children (thus lowest level) and then use the anchors as they are now? [children] => Array (...
Below are a few questions i have and at the bottom of this post the full template.
What does this do? $hierarchy_item
Code: Select all
{if !isset($hdepth) && isset($hierarchy_item)}
<h3>Hierarchy Data for {$hierarchy_item.name} ({$hierarchy_item.id})</h3>
{/if}
Code: Select all
{if $item.count gt 0}
<a href="{$item.url}">{$item.name} (IN STOCK: {$item.count})</a>
{else}
<a href="{$item.url}">{$item.name} (OUT OF STOCK)</a>
{/if}
Code: Select all
hierdata Array ( [0] => Array ( [id] => 1 [name] => Words [parent_id] => -1 [item_order] => 1 [hierarchy] => 00001 [image] => palet03.png [long_name] => Words [description] => Popular text laser cut out of a selection of materials [extra1] => [extra2] => [count] => 4 [children] => Array ( [0] => Array ( [id] => 2 [name] => Single [parent_id] => 1 [item_order] => 1 [hierarchy] => 00001.00001 [image] => iconpro.gif [long_name] => Words | Single [description] => Single popular words [extra1] => [extra2] => [count] => 4 [down_url] => http://someurl.co.za/products/hierarchy/2/58 [url] => http://someurl.co.za/products/byhierarchy/2/58 ) [1] => Array ( [id] => 3 [name] => Sets [parent_id] => 1 [item_order] => 2 [hierarchy] => 00001.00002 [image] => images.jpg [long_name] => Words | Sets [description] => Sets of popular words that often go together [extra1] => [extra2] => [count] => 0 [down_url] => http://someurl.co.za/products/hierarchy/3/58 [url] => http://someurl.co.za/products/byhierarchy/3/58 ) ) [down_url] => http://someurl.co.za/products/hierarchy/1/58 [url] => http://someurl.co.za/products/byhierarchy/1/58 ) [1] => Array ( [id] => 4 [name] => Build-It [parent_id] => -1 [item_order] => 2 [hierarchy] => 00002 [image] => [long_name] => Build-It [description] => Items that can be assembled [extra1] => [extra2] => [count] => 0 [children] => Array ( [0] => Array ( [id] => 5 [name] => Kits [parent_id] => 4 [item_order] => 1 [hierarchy] => 00002.00001 [image] => [long_name] => Build-It | Kits [description] => Kits that require assembling to form popular models [extra1] => [extra2] => [count] => 0 [down_url] => http://someurl.co.za/products/hierarchy/5/58 [url] => http://someurl.co.za/products/byhierarchy/5/58 ) ) [down_url] => http://someurl.co.za/products/hierarchy/4/58 [url] => http://someurl.co.za/products/byhierarchy/4/58 ) [2] => Array ( [id] => 6 [name] => Clocks [parent_id] => -1 [item_order] => 3 [hierarchy] => 00003 [image] => images.jpg [long_name] => Clocks [description] => Selection of wall-mounted clocks [extra1] => [extra2] => [count] => 1 [down_url] => http://someurl.co.za/products/hierarchy/6/58 [url] => http://someurl.co.za/products/byhierarchy/6/58 ) [3] => Array ( [id] => 7 [name] => Engraving [parent_id] => -1 [item_order] => 4 [hierarchy] => 00004 [image] => [long_name] => Engraving [description] => Laser engraving on a selection of items [extra1] => [extra2] => [count] => 0 [children] => Array ( [0] => Array ( [id] => 8 [name] => Glasses [parent_id] => 7 [item_order] => 1 [hierarchy] => 00004.00001 [image] => [long_name] => Engraving | Glasses [description] => Have a glass laser-engraved with a logo or text [extra1] => [extra2] => [count] => 0 [down_url] => http://someurl.co.za/products/hierarchy/8/58 [url] => http://someurl.co.za/products/byhierarchy/8/58 ) [1] => Array ( [id] => 9 [name] => Pens [parent_id] => 7 [item_order] => 5 [hierarchy] => 00004.00005 [image] => [long_name] => Engraving | Pens [description] => Laser-engrave a pen with a logo or text to create your own branded office stationary [extra1] => [extra2] => [count] => 0 [down_url] => http://someurl.co.za/products/hierarchy/9/58 [url] => http://someurl.co.za/products/byhierarchy/9/58 ) ) [down_url] => http://someurl.co.za/products/hierarchy/7/58 [url] => http://someurl.co.za/products/byhierarchy/7/58 ) )
hdepth 0
Words (IN STOCK: 4)
Build-It (OUT OF STOCK)
Clocks (IN STOCK: 1)
Engraving (OUT OF STOCK)
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}
{print_r(hierdata)}{print_r($hierdata)}{print_r('<br>')}{print_r('<br>')}
{print_r(hdepth)}{print_r($hdepth)}{print_r('<br>')}{print_r('<br>')}
{*
// 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 {if $hdepth == 0}id="products_hierarchy"{/if} class="products_hierarchy_level{$hdepth}">
{foreach from=$hierdata key='key' item='item'}
{strip}
{$class='product_hier'}
{if isset($active_hierarchy) and $item.id == $active_hierarchy}{$class=$class|cat:' active'}{/if}
{if isset($item.children)}{$class=$class|cat:' parent'}{/if}
<li{if $class != ''} class="{$class}"{/if}>
{if !($item.image === "")}{CGSmartImage src="uploads/Products/hierarchy/{$item.image}" filter_resize="p,50"}{/if}
{if $item.count gt 0}
<a href="{$item.url}">{$item.name} (IN STOCK: {$item.count})</a>
{else}
<a href="{$item.url}">{$item.name} (OUT OF STOCK)</a>
{/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>