Displaying related products
Displaying related products is a simple task, if you have followed our advice to create a separate partial for displaying a product list.
You can obtain a collection of related products with the list_related_products() method of the $product object. The following code demonstrates how you can output a list of related products using the partial you created before.
<? $related_products = $product->list_related_products()->find_all(); if ($related_products->count): ?> <h3>Related products</h3> <? $this->render_partial('shop:product_list', array('products'=>$related_products)); ?> <? endif ?>
The code checks whether any related products were assigned to the current products and outputs the header “Related products”. Then it renders the shop:product_list partial passing a result of the list_related_products() method call as a collection of products into the product list partial.
You can duplicate the shop:product_list partial and modify it if you need another way of displaying the related products.
See also:
Next: Displaying product manufacturer information
Previous: Displaying product extra options
Return to Product page
Comments
No comments posted so far.
Add your comment
Loading form...