Shopify Wishlist内存问题

时间:2016-11-01 14:25:32

标签: shopify liquid

我们的shopify应用程序中有以下代码,但它无效,我们收到错误:

液体错误:超出内存限制

代码循环遍历客户标签并检查集合中的产品ID并显示产品。

任何人都可以帮助确定问题吗?

{% include 'breadcrumb' %}
<div class="container">
  <div class="page">
    <div class="title">
      <h2>{{ page.title }}</h2>
    </div>
    <div class="page_content">
      {{ page.content }}
    </div>
    {% if customer %}
    <ul class="wishlist-items">
      <li class="head">
        <ul>
          <li class="col-1 hidden-xs">{{'wish_list.general.image' | t}}</li>
          <li class="col-2">{{'wish_list.general.item' | t}}</li>
          <li class="col-3">{{'wish_list.general.price' | t}}</li>
          <li class="col-4"></li> 
        </ul>
      </li>
      <li class="tbody">
        <ul>
        {% for tag in customer.tags %}
        {% assign the_test = '' %}
        {% capture tagID %}{{ tag }}{% endcapture %}
        {% for tag in customer.tags %}
        {% capture curTag %}{{ tag }}{% endcapture %}
        {% if curTag contains tagID %}
        {% assign tagID_tmp = tagID.size | minus:curTag.size %}
        {% if tagID_tmp == 0 %}
        {% assign the_test = tagID %}
        {% else %}
        {% assign the_test = '' %}
        {% endif %}
        {% endif %}
        {% endfor %}	

        {% for collection in collections %}
        {% paginate collection.products by collection.all_products_count %}
        {% for product in collection.products %}
        {% capture productID %}{{ product.id }}{% endcapture %}
          {% capture used %}{{ productID }} {{ used }}{% endcapture %}
        {% unless used contains productID %}
        {% assign check = tag.size | minus:productID.size | modulo:2 %}
        {% if check == 0 %}{% assign display_product = true %}{% else %}{% assign display_product = false %}{% endif %}
        {% if display_product and the_test contains productID %}
        
        {% assign variant_tmp = product.selected_or_first_available_variant  %}
        {% for variant in product.variants %}
        {% if variant.available == true and variant.price < variant_tmp.price %}
        {% assign variant_tmp = variant %}	
        {% endif %}
        {% endfor %}
        <li class="item">
          <ul>
            <li class="col-1 hidden-xs">
              <a href="{{product.url | within: collection}}" class="product-image">
                <img src="{{product.featured_image | product_img_url:'medium'}}" alt="{{product.title}}" />
              </a>
            </li>
            <li class="col-2">
              <a href="{{product.url | within: collection}}" class="product-image visible-xs">
                <img src="{{product.featured_image | product_img_url:'medium'}}" alt="{{product.title}}" />
              </a>
              <a href="{{product.url | within: collection}}" class="product-title mtop">{{product.title}}{% if product.variants.size > 1 %} - {{variant_tmp.title}}{% endif %}</a>
            </li>
            <li class="col-3"><div class="product-price"><span class="money">{{product.price | money}}</span></div></li>
            <li class="col-4">
              <div class="action">
                <div class="wishlist">
                  {% form 'customer' %}	
                  <input type='hidden' name='contact[email]' value='{{ customer.email }}'/>
                  <input type='hidden' name='contact[tags]' id='remove-value' value='x{{ tagID }}' />
                  <button type="submit" class="remove-wishlist"><i class="fa fa-close"></i></button>
                  {% endform %}
                </div> |
                <div class="addtocart">
                  {% if product.available %}
                  <form action="/cart/add" method="post" enctype="multipart/form-data">
                    <input type="hidden" name="quantity" value="1" />
                    <input type="hidden" name="id" value="{{variant_tmp.id}}" />
                    <button type="submit" class="add-to-cart"><i class="fa fa-shopping-cart"></i></button>
                  </form>
                  {% else %}
                  <a href="{{ product.url | within: collection }}" class=""><i class="fa fa-shopping-cart"></i></a>
                  {% endif %}
                </div>
                </div>
            </li> 
          </ul>
        </li>
        
        {% endif %}
        {% endunless %}
        {% endfor %}
        {% endpaginate %}
        {% endfor %}
        {% endfor %}
        </ul>
      </li>
    </ul>
    
    {% else %}
    <p>{{'wish_list.general.to_create_a_wishlist_please' | t}} <a href='/account/login'>{{'wish_list.general.login' | t}}</a> {{'wish_list.general.or' | t}} <a href='/account/register'>{{'wish_list.general.register' | t}}</a>.</p>
    {% endif %}
  </div>
</div>

1 个答案:

答案 0 :(得分:2)

这是因为许多嵌套循环。所有产品必须整理出来,因此开发人员使用了这个庞大的结构:

{% for collection in collections %}
  {% paginate collection.products by collection.all_products_count %}
    {% for product in collection.products %}
      ...
    {% endpaginate %}
  {% endfor %}
{% endfor %}

我的一个客户商店出现了这个错误。

但我们可以使用Shopify液体 all_products [&#39; the-handle&#39;]。变量

原始客户标记wishlist使用产品ID和 x 。我使用产品句柄代替产品ID而 +0 而不是 x

带有产品ID的客户代码:

12345678

x12345678

xx12345678

带句柄的客户代码:

一些副产物把手

+ 0some产物把手

+ 0 + 0some产物把手

我不得不更改代码,花了很多时间,但现在它工作正常,没有任何错误。