For Loop All Products Regardless of Page Number

berkbelcioglu
Tourist
4 0 0

Hello,

I wrote a code for one of our store and it is not working the way I want. I request your support for this.

This is a check for every item on our collections page. I get the tag that contains the base_sku name of the product and I look for the products with this tag in all products.
Then I pull the tags containing color from the products with the same base_sku and link them under the main product.
I'm using pagination here and I know I can pull up to 1000 items. What I need is to be able to loop the pagination as many times as I want per product, regardless of the page number.
Because in this way, it only checks for the first 1000 products on the first page of the collection, and when I switch to the second page, it checks the number of remaining products.

Here I have to proceed with the tags because although the products seem to be variants here, all the ones I show are separate products.
https://gyazo.com/bc139013bdb7d9ad249ca907bf4b83a1

This is an issue that I have been dealing with for a long time but could not resolve, I would be very happy if you could support me.

Best regards,
Berk

 

 

 

<div id="prod-var" class="prod-variants">
          {% for tag in product_card_product.tags %}
            {% if tag contains "BASE SKU" %}
              {% assign base_url = tag | split: "_" | last %}
            {% endif %}
            {% if tag contains "COLOUR" %}
              {% assign first_colour = tag | split: "_" | last %}
            {% endif %}
        	{% if tag contains "SIZE" %}
              {% assign first_size = tag | split: "_" | last %}
            {% endif %}
          {% endfor %}
          <div class="variant-all-div">
              {% paginate collections.all.products by 1000 %}
                {% for product in collections.all.products %}
                  {% for tag in product.tags %}
                    {% if tag contains base_url %}
                        {% for tag in product.tags %}
                          {% if tag contains "COLOUR" %}
                            {% assign colour = tag | split: "_" | last %}
                          {% endif %}
                        {% endfor %}
                        {% for tag in product.tags %}
                          {% if tag contains "SIZE" %}
                            {% assign size = tag | split: "_" | last %}
                          {% endif %}
                        {% endfor %}
                        {% if first_colour == colour and first_size == size%}{% continue %}{% endif %}
                        <div class="variant-div">
                          <a class="collec-variant" href="{{product.url}}"><img style="width: 30px; height: 30px;" src="{{ product.featured_media | img_url:'30x30' }}"></a>
                          <span class="tooltiptext">{{ colour }}</span>
                        </div>
                    {% endif %}
                  {% endfor %}
                {% endfor %}
              {% endpaginate %}
          </div>
        </div>

 

 

 

Shopify Frontend Developer at PATH
Reply 1 (1)

Jason
Shopify Expert
11190 225 2282

That does not look like efficient code at all and there's likely better ways to handle it. For the moment I'll ignore that.

 

Pagination will only be called once on a page since it's rendered via the server with a Collection Drop being created for that view. IF you need to call it again on the same page that data should be coming from AJAX calls instead. So the call will be made in the background to get page 2, 3, 4, etc. When you do that you really shouldn't need to call 1000 products which will dramatically increase your page load times.

★ I jump on these forums in my free time to help and share some insights. Not looking to be hired, and not looking for work. http://freakdesign.com.au ★