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.