【发布时间】:2017-07-05 07:22:20
【问题描述】:
我想遍历商店中最畅销的产品并将它们添加到 Javascript 对象中。
类似这样的:
<script>
var bestSelling = [];
{% assign all = collections.all %}
{% assign best_selling = all.products | sort: 'best-selling' %}
{% for product in best_selling %}
var thisProduct = {
"handle": "{{ product.handle }}",
"id": "{{ product.id }}",
"url": "{{ product.url }}",
"image": "{{ product.featured_image | img_url: 'x700' }}",
"price": "{{ product.price | money }}",
"title": "{{ product.title }}",
}
bestSelling.push(thisProduct);
{% endfor %}
那么 bestSelling 将是一系列产品作为最畅销的对象。
我知道我可以创建所有产品的集合并通过在 shopify 管理面板中畅销来过滤它们,但我试图避免这条路线。我真的只是在寻找一种对现有集合进行排序的方法。
那么在液体中,我如何通过畅销来过滤收藏?
【问题讨论】:
标签: javascript json shopify liquid