Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Tag-Based Product Recommendation

Tag-Based Product Recommendation

Saba13
Shopify Partner
23 2 5

Good day,

 

I'm creating a tag-based recommendations section on a client's website. The section is suppose to display products that have the same tag as the current product on the product page.

 

My logic is: 
1. Iterate through the current products tags.

2. Iterate through each product in the store (calling this rec_product).

3. Iterate through the rec_products tags.

4. Check if the rec_product's tag is equal to the current product's tags.

5. If equal, check if the product hasn't already been rendered.

6. If not rendered, display it.

 

This is my code:

{%- assign products_rendered = '' | split: '|' -%}
            {%- for _tag in product.tags -%}
              {%- for rec_product in collections.all.products -%}
                {%- for tag in rec_product.tags -%}
                  {%- if _tag == tag -%}
                    {%- unless products_rendered contains rec_product.id -%}
                      {%- render 'product-card',
                        product: rec_product,
                        stacked: section.settings.stack_products,
                        background: section.settings.product_card_background,
                        text_color: section.settings.product_card_text_color,
                        show_badges: true
                      -%}
                    {%- endunless -%}
                    {%- assign products_rendered = products_rendered | append: rec_product.id | append: '|' -%}
                  {%- endif -%}
                {%- endfor -%}
              {%- endfor -%}
            {%- endfor -%}

 

My code is only working for some products and I'm not receiving any error. I feel like there maybe an error in my logic instead.

 

Example:

 

Product Pasabahce Hiball Glass Tumbler 230ml Clear 40074 (bubblesplastics.co.za) doesn't show any recommeded products even though it's tagged: 

Saba13_0-1710494105531.png

 

And there are products with at least one of the tags:

Saba13_1-1710494188911.png

 

Theme: Impact 4.7.1 (Impact Theme - Home - Ecommerce Website Template (shopify.com))

Preview Link: https://gj6j1wb7oqwnne1e-52573339831.shopifypreview.com (not on the published theme because the section is not working).

 

Any assistance or advise will be greatly appreciated, thank you.

Replies 3 (3)

Saba13
Shopify Partner
23 2 5

Hedden_LLC
Tourist
7 0 0

Did you end up getting it to work?  Preview link doesnt seem to work.

Best regards,



Jonathan Hedden

CEO/President

FLYCLOTHING, LLC

3324 E RAY RD #1715

HIGLEY, AZ 85236-4500

Phone: 480.422.7350 | Fax: 480.422.7350 | Cellular: 480.406.1163 | Toll Free: 888-359-2568

https://linkpop.com/flyclothing

Celebrating 20 years in business.
Saba13
Shopify Partner
23 2 5

Yes. I had a freelance dev help me. He managed to figure it out with some trial and error. You can see it on the live website now: https://bubblesplastics.co.za/.