ECommerce suite: hierarchy

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
wmdvanzyl
Forum Members
Forum Members
Posts: 214
Joined: Fri May 06, 2011 12:48 pm

ECommerce suite: hierarchy

Post by wmdvanzyl »

Hi All.

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}
then do this:

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}
I can successfully display the top level (i do not invoke the template again), but the links to the items still take you to the summary.

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}
Here are the anchors i want to change:

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}
Output from print_r:

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)
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}
    {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>
Last edited by wmdvanzyl on Tue Mar 25, 2014 11:11 am, edited 2 times in total.
wmdvanzyl
Forum Members
Forum Members
Posts: 214
Joined: Fri May 06, 2011 12:48 pm

Re: ECommerce suite: hierarchy

Post by wmdvanzyl »

Found a few posts that could be useful:

http://dev.cmsmadesimple.org/bug/view/7999

http://forum.cmsmadesimple.org/viewtopi ... hy#p309205

I now have it set up that on the products page only the top level hierarchy-items are showing. If there is an hierarchy-item which has an actual item assigned to it, then that item's URL is correct and clicking on it takes you to the item's summary page. However, the hierarchy-items that only contain more hierarchy-items (which in turn have items assigned to them) do not have proper URL's. I have tried using $item.url_down but this does not work. So things appear fine now, i just need to have the URL of those "purely" hierarchical items pointing to their children.

This is what i have thus far:

Products page:

Code: Select all

{Products action='hierarchy'}
Hierarchy Template

Code: Select all

{* hierarchy report template *}

{* breadcrumbs *}
{if empty($products_path_names)}

  {assign var='products_pagelimit' value=$actionparams.pagelimit|default:'25'}
  {assign var='products_pagenb' value=$actionparams.page|default:'1'}
  {assign var='products_parent' value=$actionparams.parent|default:$actionparams.hierarchyid}
  {assign var='products_hier_info' value=$Products->GetHierarchyInfo($products_parent)}
  {assign var='products_path_ids' value='.'|explode:$products_hier_info.hierarchy}
  {assign var='products_path_names' value=' | '|explode:$products_hier_info.long_name}
  {cms_selflink page=$page}
  {if !empty($products_parent)}
      {foreach from=$products_path_ids  key='key' item='tmp'}
        » {if !$smarty.foreach.default.last}{module_action_link module='Products' action='hierarchy' text=$products_path_names.$key page=$page_alias parent=$tmp|ltrim:'0' pagelimit=$products_pagelimit}{else}{$products_path_names.$key}{/if}
      {/foreach}
  {/if}
{/if}

{if empty($products_list)}
{capture assign='products_list'}{Products hierarchy=$products_hier_info.long_name|cat:'*' pagelimit=$products_pagelimit  parent=$products_parent page=$products_pagenb}{/capture}
{/if}
{* end breadcrumbs*}

{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 {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 isset($item.children)}
        {if $item.count gt 0}
            {if !($item.image === "")}{CGSmartImage src="uploads/Products/hierarchy/{$item.image}" filter_resize="p,50"}{/if}
            <a href="{$item.url}">{$item.name|cat:" (IN STOCK: "|cat:$item.count|cat:")"}</a>
        {else}
            {if !($item.image === "")}{CGSmartImage src="uploads/Products/hierarchy/{$item.image}" filter_resize="p,50"}{/if}
            {$item.name|cat:" (OUT OF STOCK)"}
        {/if}
    {else}
        {if $item.count gt 0}
            {if !($item.image === "")}{CGSmartImage src="uploads/Products/hierarchy/{$item.image}" filter_resize="p,50"}{/if}
            <a href="{$item.url}">{$item.name|cat:" (IN STOCK: "|cat:$item.count|cat:")"}</a>
        {else}
            {if !($item.image === "")}{CGSmartImage src="uploads/Products/hierarchy/{$item.image}" filter_resize="p,50"}{/if}
            {$item.name|cat:" (OUT OF STOCK)"}
        {/if}
    {/if}
  
  </li>
{/strip}
{/foreach}
</ul>

wmdvanzyl
Forum Members
Forum Members
Posts: 214
Joined: Fri May 06, 2011 12:48 pm

Re: ECommerce suite: hierarchy

Post by wmdvanzyl »

Posted in Help Wanted (commercial) board
Post Reply

Return to “Modules/Add-Ons”