Shopify JSON数组返回结果,但结果为空 [英] Shopify JSON array returning results but some empty results

查看:191
本文介绍了Shopify JSON数组返回结果,但结果为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想拉回可用的结果,但是返回的是json响应,例如null,null,null,result,result.这是代码:

I am wanting to pull back only results that are available but it is returning in the json response null,null,null,result, result for example. Here is the code:

{% capture results %}
  {% for item in search.results %}
    {% assign product = item %}
    {% if product.available == true %}
      { 
        "title"    : {{ product.title | json }},
        "url"      : {{ product.url | within: product.collections.last | json }},
        "thumbnail": {{ product.featured_image.src | product_img_url: 'thumb' | json }},
        "available": {{ product.available | json }}
      }
    {% endif %}
    {% unless forloop.last %},{% endunless %}
  {% endfor %}
{% endcapture %}

任何人都知道我需要做些什么,以不返回空结果,而只返回可用的真结果,并排除available(false)

Anyone know what i would need to do to not return the null results but only the available true ones and exclude the available(false)

它返回9个结果,其中7个不可用,并且会显示2,但如果您知道我的意思,则需要它返回9个可用9中的2个.

It returns 9 results, 7 of which are not available and would show 2 but need it to return 9 available not 2 out of the 9 if you know what i mean.

推荐答案

您可以在此处执行以下两项操作:

There are two things you can do here:

  1. 您可以在Shopify之外创建搜索应用.该应用程序将获取所有产品,检查每个产品的可用性状况,然后以10、20、30等产品的数组形式返回搜索结果,如果您打算进行分页,则可以将其存储在本地会话中.

  1. You can create a search app outside of Shopify. This app will fetch all the products, check each product for availability condition and return the search results in arrays of 10, 20, 30 etc products, which you can store locally the session if you intend to do pagination.

对于商店中可用的每种产品,添加标签 istock (有库存),对于那些不可用的产品,添加标签 库存 .搜索时,只需将 + istock 附加到搜索查询中即可.它将始终仅返回与搜索词匹配并带有标签"istock"的产品.

For each product that is available on your store, add a tag istock (In Stock) and for those that are not available have a tag ostock. While searching, just append +istock to the search query. It'll always return only the products matching the search term and with the tag "istock".

这篇关于Shopify JSON数组返回结果,但结果为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆