Warning: Cannot modify header information - headers already sent by (output started at /www/wwwroot/sbboke.com/wp-content/plugins/wordpress-seo/src/integrations/front-end-integration.php:409) in /www/wwwroot/sbboke.com/wp-content/themes/pacify/content-single.php on line 5

Magento2-如何使用Magento_Catalog / js / price-box在模板中设置价格格式?

1)Magento_Catalog/js/price-box用于格式化价格金额。

  function formatPrice(amount, format, isShowSign) {
     ......
  }
  • amount:是价格金额(是一个数字)
  • format是一个对象,有一些属性:decimalSymbolgroupLengthgroupSymbolpatternprecision,...一结帐页面,我们可以检查window.checkoutConfig.priceFormat
  • isShowSign:是布尔值。将+/-在价格上显示(加/减)符号。

2)使用价格框js的一个很好的例子是在一页结帐中。

结帐页面之一,结帐配置存储在全局Js变量中。我们可以在浏览器控制台中签入:window.checkoutConfig

vendor/magento/module-checkout/view/frontend/web/js/view/summary/abstract-total.js
vendor/magento/module-checkout/view/frontend/web/js/view/estimation.js
vendor/magento/module-checkout/view/frontend/web/js/view/cart/shipping-rates.js

       /**
         * Format shipping price.
         * @returns {String}
         */
        getFormattedPrice: function (price) {
            return priceUtils.formatPrice(price, quote.getPriceFormat());
        },

有一条注释:quote.getPriceFormat()window.checkoutConfig.priceFormat对象获取值。

[我们可以使用:

<script>
        window.orderPriceFormat = <?php /* @escapeNotVerified */ echo $this->helper('Magento\Tax\Helper\Data')->getPriceFormat($block->getStore()); ?>;
</script>

相关文章

0 0 投票数
文章评分
订阅评论
提醒
0 评论
内联反馈
查看所有评论