Quick design tip: show related products in your store

Sometimes it can be nice to show related products on a product page, so that your visitors can more easily browse your store. To do so, we’ll be using product tags to match products to each other. To start, add a couple of products to your store and don’t forget to fill in the “tags” field with tags that match the products, like “coolstuff”. I’m just making up a tag here, use anything that’s logical for your own store and products.

In your “product” template, load up the current product as follows:

{% set current_product = product.get() %}
{{ current_product.name }}

Next, we will get a list of products, but only those that match the tags that have been entered in our currently loaded product. Here’s the snippet you can use to do just that:

{% set related_products = product.getList({"tag":current_product.tags}) %}
{% for p in related_products %}
{{ p.name }}
{% endfor %}

There you have it. Related products in just a few lines of template code.

If you’d like to see more of these little code snippets, let us now in the comments below. Enjoy!