Page 1 of 1

LISE - drill down to other LISE using LISE Instance Item

Posted: Thu Jul 07, 2022 7:45 am
by przemo
Hi,
First of all I have written this topic and this topic on this forum but I did not find a solution of my problem.

First Instance is LISEproduct, second LISEmaterials.
In LISEmaterials there is Category field definition to group items by category like wood, metal, aluminum and so on.
In LISEproduct there is Material field definition (alias: material) type: LISE Instance Item, sub-type jquery multiselect.

In a detail view of each product I drill down to materials of this specific product by using

Code: Select all

{LISEmaterials include_items="{$item->material}" template_summary="product-card"}
And here I would like the materials to be divided into their categories, not loosely listed like:
- material 1, category: wood
- material 2, category: metal
- material 3, category: wood
- material 4, category: wood
(the aluminum category is not displayed because no material has been selected)

Put simply, I want to get this effect:

Category Wood:
- material 1
- material 3
- material 4
Category Metal:
- material 2

Anyone have an idea how to do this?

Re: LISE - drill down to other LISE using LISE Instance Item

Posted: Thu Jul 07, 2022 2:13 pm
by DIGI3
I think you could do this by calling category mode for the result

Code: Select all

{LISEmaterials action=category show_items=true ... }
Possibly include_items could be an array converted to csv so you're only calling it once, but I'd have to experiment with that.

If you wanted to continue with the method you're already using, you should be able to sort by category, then do the category breaks in your template with a bit of Smarty logic.

Re: LISE - drill down to other LISE using LISE Instance Item

Posted: Thu Jul 07, 2022 4:23 pm
by przemo
hi!

Code: Select all

{LISEmaterials action=category show_items=true ... }
This would be great solution, but unfortunately it lists all the categories and content - unrelated to the product we're browsing at the moment.
As you know, I cannot use the additional parameter like

Code: Select all

{LISEmaterials action=category show_items=true include_items=$item-> material}
So the question is how to do it later (in the category template) to display categories and materials belong to them, but only related to the currently viewed product?

Re: LISE - drill down to other LISE using LISE Instance Item

Posted: Thu Jul 07, 2022 4:55 pm
by DIGI3
In your item, create a csv variable with all the related categories, and use that as the category= value. If you need further matching (whatever is used to determine if it's relative to your product) then you'd do an if in the category template, or give them classes with the relationship values and hide them as needed.

Re: LISE - drill down to other LISE using LISE Instance Item

Posted: Thu Jul 07, 2022 5:42 pm
by velden
Try this code in your product-card template:

Code: Select all

{* array to store items per category ID *}
{* requires one, and only one, category per item *}
{$tmpArray=[]}

{* iterate all items and store them in the array under their category id *}
{if $items|@count > 0}
  {foreach from=$items item=item}
     {$tmpArray[$item->fielddefs.category->value][]=$item}
  {/foreach}
{/if}

{* sort array by category ID!!! *}
{$dummy=$tmpArray|@ksort}

{* iterate found category IDs *}
{foreach from=$tmpArray key=catid item=catitems}
  {* load the the category object to get its name  *}
  {LISELoader item='category' value=$catid assign=cat}
  <h3>{$cat->name}</h3>
  <ul>
  {* finally iterate the items for the category and print their title *}
  {foreach from=$catitems item=item}
    <li>{$item->title}</li>
  {/foreach}
  </ul>
{/foreach}

Re: LISE - drill down to other LISE using LISE Instance Item

Posted: Fri Jul 08, 2022 7:25 am
by przemo
Thank you Velden - it works!
I really dont know how or why ::) but that solves my problem.
I owe you a "cup of coffee".

DIGI3 - I appreciate you wanting to help,

thank you one more time guys.