Page 1 of 1

[SOLVED] Products: How to build related products

Posted: Thu Nov 21, 2013 1:11 pm
by Guido
Hi,

In my detail product template, I would like to fill a DIV with all products from the current category. So I could recall the {Products} tag again like:

Code: Select all

{Products summarytemplate="list" category="$category->name"}
But since a product can belong to multiple categories, I would like to create a comma separated list of categories at the top of my detail template and re-use it further on, since the category handler will take multiple categories in a comma separated list.

Problem is, I not a good programmer. I've been trying foreach loops and |implode and |explode modifiers for some hours now, but can't get it right..

Anyone have a clue?

Re: Products: How to build a comma separated list of categor

Posted: Thu Nov 21, 2013 1:27 pm
by Rolf
Look at my blog how I made a tagcloud https://www.cmscanbesimple.org/blog/add ... ews-module

Re: Products: How to build a comma separated list of categor

Posted: Thu Nov 21, 2013 1:33 pm
by Guido
Hey Rolf,

I sure will. In the meantime using

Code: Select all

<pre>{$entry|print_r}</pre>
I found that the Products module creates an array called "catnamearray" out-of-the-box. Devious...

Re: Products: How to build a comma separated list of categor

Posted: Thu Nov 21, 2013 2:03 pm
by Guido
And now I've found an even better way. It seems Calguy created a new (great) modifier:

Code: Select all

{Products action="default" productlist="$test"}
You can create a custom field now, enter a comma separated list of related product (without regard of category or hierarchy) and parse this on to a var by using

Code: Select all

{assign var='test' value=$entry->fields.relatedproducts->value}
Now you can output a summarytemplated list of related products on your detail page.

One more question though: If for some reason a user enters something else than a comma separated list in the productmanager, an SQL error will show up and break the site. Is there a way smarty can check (via an {if} statement) for the field to be the correct format?