在 Stencil 条件语句中显示产品价格时出现问题

Trouble Displaying a Product's Price in Stencil Conditional Statement

我在 BigCommerce 中使用 Cornerstone 主题。在我的产品页面上,我需要隐藏定价,除非最终用户已登录。BigCommerce 具有此功能,但要么全有要么全无,我只想限制某些商品显示其价格。我在产品级别使用名为 HidePrice 的自定义字段。此自定义字段为我网站上的每个产品定义了 True 或 False。我需要考虑三个条件...

  1. 最终用户已登录:无论 HidePrice 值是多少都显示价格
  2. The product's HidePrice value = false: 显示产品的价格
  3. 产品的 HidePrice 值 = true 且最终用户未登录:禁止显示产品价格并显示备用消息“太低无法显示”。

这是我的代码,但效果不佳...

<div class="productView-price">
    {{#if customer}}
        {{#if product.can_purchase}}
            <p class="productView-price">
                <span>Price: {{product.price.without_tax.value}}</span>
            </p>
        {{/if}}
    {{else}}
        {{#filter product.custom_fields 'HidePrice' property='name' }}
            {{#if (toLowerCase value) '==' 'true'}}
                <div class="too-low-to-show">This product is priced too low to show!</div>
            {{else}}
                <p class="productView-price">
                    <span>Price: {{product.price.without_tax.value}}</span>
                </p>
            {{/if}}
        {{/filter}} 
    {{/if}}
</div>

我似乎无法工作的部分是上面的条件 #1(产品的 HidePrice 值 = false:显示产品的价格)。条件 #2 和 #3 工作得很好,但当满足条件 #1 的要求时,价格根本不会显示。奇怪的是,我在价格把手显示之前预先添加的“价格:”标签,但 BigCommerce 似乎忽略了价格把手本身。我发现如果我在条件语句之外使用相同的价格手柄,它会呈现在页面上。我对此感到困惑。任何帮助将不胜感激。谢谢!

我认为这里的问题只是范围。一旦你输入过滤条件,你就离开了全局范围,进入了product.custom_fields范围。您不再有权访问产品对象。一个简单的解决方法应该是通过在 product.price.

前面附加“../”来返回上一级
<div class="productView-price">
{{#if customer}}
    {{#if product.can_purchase}}
        <p class="productView-price">
            <span>Price: {{product.price.without_tax.value}}</span>
        </p>
    {{/if}}
{{else}}
    {{#filter product.custom_fields 'HidePrice' property='name' }}
        {{#if (toLowerCase value) '==' 'true'}}
            <div class="too-low-to-show">This product is priced too low to show!</div>
        {{else}}
            <p class="productView-price">
                <span>Price: {{../product.price.without_tax.value}}</span>
            </p>
        {{/if}}
    {{/filter}} 
{{/if}}
</div>