【问题标题】:Trouble Displaying a Product's Price in Stencil Conditional Statement在模板条件语句中显示产品价格时遇到问题
【发布时间】:2021-07-27 22:45:09
【问题描述】:

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

  1. 最终用户已登录:无论 HidePrice 值为多少,都显示价格
  2. 产品的 HidePrice 值 = 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 忽略了。我发现如果我在条件语句之外使用相同的价格把手,它将呈现在页面上。我对这个感到困惑。任何帮助将不胜感激。谢谢!

【问题讨论】:

    标签: bigcommerce


    【解决方案1】:

    我相信这里的问题只是范围。输入过滤条件后,您就离开了全局范围并进入了 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>
    

    【讨论】:

    • 这太有道理了 :) 谢谢马特!我会试一试并发布我的结果。
    • 注意:根据您的主题使用的 Handlebars 版本,您可能需要第二个“../”(../../product.price...)
    • 谢谢马特!你的建议非常有效。多亏了你,我现在已经完全可以使用它了:)
    猜你喜欢
    • 1970-01-01
    • 2021-05-18
    • 2012-12-25
    • 2011-03-14
    • 1970-01-01
    • 1970-01-01
    • 2022-12-14
    • 2018-07-31
    • 1970-01-01
    相关资源
    最近更新 更多