Getting a Liquid Error, Memory limit exceeded

Highlighted
New Member
3 0 0

On my productions store I have over 300 products and have a custom built theme that displays these products.  I am working with a company that is converting automotive data for me into the Shopify import format (using API's).  In a test store they have loaded over 5000 products.  Using a free theme, they have built a very simple site for me to review the completeness of the data. All the products are in a single location "Catalog" . when I open the Catalog, I see all the products.  When I uploaded my custom theme and use the same Catalog to look at the data, I then get the Shopify error that says "Liquid Error.  Memory limits exceeded".  What I can't understand is how with a free theme I can view 5000 products in one catalog/collection, but when using my custom theme, I can't.

To explore further, on the devlopment site using my custom theme, I build several smart collections.  In two of them I put about 100 products, I also created a smart collection called "Everything" and made it contain any product with a weight greater than 0.   If you guessed, that I would be able to open the collections with 100 items in them, you would be correct.  But the collection called Everything resulted in the same Shopify error message.

Any thoughts?  Thanks in advance.

Bob

0 Likes
Highlighted

Hi Bob,

I think it is necessary to optimize the code in your productions custom theme. It might use a loop in a loop or something similar and this number of iterations goes beyond the limit.

The same error was discussed in this topic: (https://ecommerce.shopify.com/c/shopify-discussion/t/liquid-error-memory-limits-exceeded-270646). But in that case, the error appeared because of too many customers tags.

 

Best,
Arthur

Shopify subject matter expert | Founder at GenovaWebArt | Full-services shopify agency | info@genovawebart.com
0 Likes
Highlighted
Tourist
9 0 1

@Bob_Kirk @Arthur_Korniyen  - I had same issue on client's store, when I looked onto main theme js file I found nested loop which looks like this:

{% for collection in collections %}
    {% for product in collection.products %}
       {% for variant in product.variants %}
           all_variants[{{ variant.id }}] = {
            inventory_policy: "{{ variant.inventory_policy }}",
             inventory_management: "{{ variant.inventory_management }}",
            inventory_quantity: {{ variant.inventory_quantity }}
         };
      {% endfor %}
    {% endfor %}
{% endfor %}

By removing outer two loop it works PERFECT for me, and "Memory Limits Exceeded"  issue has been resolved  as well and theme is working perfectly Awesome. This is what I replaced:

       {% for variant in product.variants %}
           all_variants[{{ variant.id }}] = {
            inventory_policy: "{{ variant.inventory_policy }}",
             inventory_management: "{{ variant.inventory_management }}",
            inventory_quantity: {{ variant.inventory_quantity }}
         };

 Hope it help :)

Regards,
Khalid 

0 Likes
Highlighted
Shopify Partner
15 0 0

Hey Arthur, i think ive just ran into the same problem with the tagging issue on my theme, its a non shopify theme so i was wondering if this code fix will work ?

0 Likes
Highlighted
Excursionist
14 0 3

I have same problem, but with different languages. For example I have multilanguage webste site.com and it works perfect, but it doesn't work on site.com/de. It shouldn't be problem of theme.

0 Likes