Add a Related Products Text Field
This is where you will enter a comma separated list of the product IDs for each related product.
1. Navigate to Content » Product Manager » Field Definitions
2. Click 'Add A Field'
3. Name: relatedproducts, Prompt: Related Products, Type: Text Input
Add a 'Related Products' Section to the Detail Template
Using the 'Sample' detail template, insert the following code at line 40 (just above the attributes):
Code: Select all
{foreach from=$entry->fields key='name' item='field'}
{if $field->name == 'relatedproducts' && $field->value != '' && $field->value != 0}
{assign var='relatedproducts' value=","|explode:$field->value}
<h4>{$field->prompt}</h4>
{foreach from=$relatedproducts item='relatedproduct'}
{Products action='details' productid=$relatedproduct detailtemplate='Related-Products'}
{/foreach}
{/if}
{/foreach}
Create a new detail template
1. Navigate to Content » Product Manager » Detail Templates
2. Click 'New Template'
3. Template Name: Related-Products
Option 1: If you want to show a thumbnail of the related products:
Code: Select all
<div class="related-product">
{foreach from=$entry->fields key='name' item='field'}
{if $field->type == 'image' && isset($field->thumbnail) && $field->name == 'image01'}
<img src="{$entry->file_location}/{$field->thumbnail}" alt="{$field->value}"/>
{/if}
{/foreach}
<div class="related-product-title">
<a href="{root_url}/index.php?mact=Products,cntnt01,details,0&cntnt01productid={$actionparams.productid}&cntnt01returnid={$page_id}">{$entry->product_name}</a>
</div>
{if $entry->price ne '' && $entry->price ne 0}
<div class="related-product-price">
{$currency_symbol}{$entry->price}
</div>
{/if}
</div>
Code: Select all
<li>{module_action_link module='Products' action='details' productid=$entry->id text=$entry->product_name}</li>
Code: Select all
<h4>{$field->prompt}</h4>
<ul>
{foreach from=$relatedproducts item='relatedproduct'}
{Products action='details' productid=$relatedproduct detailtemplate='Related-Products'}
{/foreach}
</ul>
Notes:
As of this writing, the hyperlinks inside the Related-Products detail template do not support pretty urls.
My first version of this workflow used an attribute list which was much more cumbersome than this method.
Thanks to tyman00 for all the great suggestions below.