0

I am having a strange issue in my product listing template. Basically I have 2 channels. First channel say items stores the product information like product name, sku, company id etc and other channel say images stores the images information like sku, company id image URL for the products. Please note that sku and company id also exists in images channel which relates both items and images channel.

So I create a product listing page which have a channel entry loop like this

{exp:channel:entries channel="items" orderby="date" limit="15" paginate="bottom" sort="DESC"} {title} {/exp:channel:entries}

I need to show related image of this channel entry i.e. image which have same company id and sku as this entry. So I added an embed template to it so my working code snippet is this

{exp:channel:entries channel="items" orderby="date" limit="15" paginate="bottom" sort="DESC"}

     {embed="path/item-image" company_id="{company_id}" sku="{stock_keeping_unit}"}

{/exp:channel:entries}

Here is how embed template looks :

{exp:channel:entries channel="images" dynamic="no" limit="1" orderby="random" search:image_company_id="={embed:company_id}" search:image_stock_keeping_unit="={embed:sku}" }

 {if no_results}
    <img alt="" class="item-image" src="/assets/images/default-product-image.jpg">
 {/if}
 <img alt="item-image" class="item-image" src="{image_url}">

{/exp:channel:entries}

Now the issue is embed template keeps adding the same image with every loop. I have verified that company id and sku is different for each entry but it show the first image for all the items.

I have searched on Google where people having similar issue fixed it by adding random but random does not have any effect on my code. I can only think that EE is not calling the identical template more than once for optimization. I have also tried stash with snippet as I need to pass variables to the embedded code but it also returns the same image over and over.

Has anyone had this issue before, and if so, let me know how can I avoid it.

0

It feels like your search: isn't firing as you are expecting. If in your embed template, you display {image_url} as text, is it correct?

Also put some text in the no_results conditional so you can tell if that is what is always returning, or not.

The SKU should be enough for a unique identifier. Try the search with just the SKU.

If you hard code a SKU into the embed template, does it return the expected result? Get the embed template working as expected with hard coded values first. Then when you emded it and pass values for the search, turn on template debugging and check that the correct values are being passed as expected.

| improve this answer | |
  • I have tested embedded template with hard coded values. It searches correctly. The issue is embed template does not get called again with next iteration. It seems to be loading the same template again and again. – Neeraj Sharma Jun 25 '15 at 8:26
  • Do you have tag caching or template caching turned on? – Peter Lewis Jun 25 '15 at 18:21
  • 1
    I completely forget to check the template cache preference. Setting it to no made it working. – Neeraj Sharma Jun 26 '15 at 14:23
0

Why would you have 2 separate channels for products and images? Since an image can be seen as a property of a product to me it seems logical that they are in the same channel. Plus it would save an embed and other overhead in programming this. For the company i would suggest have a company channel which holds the company information, logo, etc. And you could link this from a relationship field in the products field group

| improve this answer | |
  • I need them as separate channels as I import data via two separate csv using datagrab. One csv import product info other has images only. – Neeraj Sharma Jun 25 '15 at 8:24
  • datagrab is excellent for combining separate csv's into a single channel. as long as you have a unique id you can run different imports into the same DB/channel, updating the fields you need updated – Jelle Dijkstra Jun 25 '15 at 13:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.