0

我用了

{% if sale %}
    <strike id="fullprice" style="display: block;">
        {{ product|discount_price:""|currency }}
    </strike>
{% endif %}
<span id="price">{{ product|discount_price:sale|currency }}</span>

这在没有销售的情况下有效,即 discount_price: sale |currency 并引发异常

渲染时捕获 VariableDoesNotExist:在...中查找键 [sale] 失败

显示销售价格和非销售价格很重要。我怎样才能做到这一点。

4

1 回答 1

1

如果您使用按产品分配的单独销售,您应该使用

{{ product|sale_price|currency }}

或者您可以替换sale_pricetaxed_sale_price或者untaxed_sale_price如果您想在发票上明确设置一个。

如果您的意思是整个站点的折扣,例如为登录用户创建特殊折扣,您应该使用 discount_price:storewide_sale,因为上下文处理器创建的这个“sale”变量已在多个用户的请求下重命名为 storewide_sale。

于 2012-04-06T16:21:56.317 回答