I am trying to show best products based on collections . So in collections I have created a product meta field which stores the list of products . When I am retrieving the list in product page then its not showing the data .
{% assign first_collection = product.collections | first %}
{% assign collection_handle = first_collection.handle %}
<p>Collection Name: {{ collections[collection_handle].title }}</p>
<div class="related-products-wrapper">
{% assign related_products = collections[collection_handle].metafields.custom.test %}
{{ collections[collection_handle].metafields.custom.test }}
{% if related_products %}
<h3>You might also like:</h3>
<div class="related-product-list">
{% for related_product in related_products %}
<a href="{{ shop.url | append: '/products/' | append: related_product.handle }}">
<div class="related-product">
<div class="related-product-image">
<img src="{{ related_product.featured_image | img_url: 'medium' }}" />
</div>
<div class="related-product-name">{{ related_product.title }}</div>
<div class="related-product-price">{{ related_product.price | money }}</div>
</div>
</a>
{% endfor %}
</div>
{% endif %}
Here ” collection_handle” is fetching the handle of collection which is attached to the product , so want to show the products which are attached to that particular collection .
output