Display products as swatches based on Metafields

Highlighted
Shopify Partner
1 0 1

Hello, Shopify community. 

I am working on one project and trying to display products as swatches on the products page based on Metafields.

I have created this code: 

            {% assign current_device_model = product.metafields.device.model %}
            {% assign current_product_id = product.id %} 
          
            <div class="product-color-option">
            <div class="product-color-option__list">
            <div class="header"><b>Color</b> - {{product.title}}</div>
            {% for product in collections.all.products %}
            {% unless product.metafields.device.model != current_device_model %}
             <a class="product-color-option__link {% if product.id == current_product_id %}product-color-option__link--active{% endif %}" href="{{collection.url}}{{product.url }}" title="{{ product.title }}" product-id="{{product.id}}">
             <div class="product-color-option__image" style="background-image: url({{ product.featured_image.src | product_img_url: '100x' }});"></div>
             </a>
            {% endunless %}
            {% endfor %}
            </div>
            </div>

The idea is to check the current value of Metafield and display all other products that have the same Metafield value. 

It's working, but only with the first 50 products. 

 

Do you have any ideas on how I can check all products (not first 50) and display products with the same Matfield ?

1 Like
Highlighted
New Member
1 0 0

Has anyone found a solution for this? I've got the same problem.

0 Likes