【问题标题】:donation counter on starting page起始页上的捐款柜台
【发布时间】:2019-06-20 15:54:26
【问题描述】:

我需要一个捐款计数器(总金额),它显示在起始页和特定页面上。我的问题是,我包含了一个 sn-p 来获得总捐款,而这些捐款来自一个特定的产品。我设法获得了捐款总额,我可以将其显示在产品页面上。但我想在起始页和特定页面上显示它。我写了一个 product-sold-count.liquid 如下:

{% assign productStartCount = product.metafields.stock.initial | times:1 %}
{% if productStartCount > 0 %}
{% assign productInventory = product.variants.first.inventory_quantity %}
{% assign totalSum = productStartCount | minus:productInventory | times: product.price | times: product.metafields.donation.percent | divided_by: 10000 %}
<p>{{ totalSum }} € were donated until now!</p>
{% endif %}

现在我想把这个totalSum 放到另一个页面上,还是更可能放到起始页和其他页面上?我试过:{% include 'product-sold-count' %} 在特定的液体上,如 page.liquid 或 theme.liquid 但这不起作用。我怎样才能做到这一点?

【问题讨论】:

    标签: shopify shopify-app shopify-template


    【解决方案1】:

    问题出在产品页面上,您有变量product。但在其他页面上,这个变量的有效期更长。

    为了获得所有产品的总数,您可以对每个产品重复上述代码并获得所有产品的总和。请注意,Shopify 提供 all_products 变量,但每页限制为 20 个产品。您可以使用 collection.products 如果它在一个集合上(或者,将所有捐赠产品分配给捐赠集合,然后获取该集合的所有产品)

    {% assign allProductCount = 0 %}
    
    {% for product in  all_products %}
      {% assign productStartCount = product.metafields.stock.initial | times:1 %}
      {% if productStartCount > 0 %}
        {% assign productInventory = product.variants.first.inventory_quantity %}
        {% assign totalSum = productStartCount | minus:productInventory | times: 
      product.price | times: product.metafields.donation.percent | divided_by: 10000 %}
    
        {% assign allProductCount = allProductCount | plus: totalSum %}
      {% endif %}
    
    {% endfor %}
    
    <p>{{ allProductCount }} € were donated until now!</p>
    
    

    【讨论】:

      猜你喜欢
      • 2015-03-22
      • 2014-07-16
      • 2014-11-04
      • 2012-04-29
      • 2014-12-23
      • 2013-09-28
      • 1970-01-01
      • 2017-05-22
      • 1970-01-01
      相关资源
      最近更新 更多