微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Shopify 价格变化方程

如何解决Shopify 价格变化方程

我正在使用 Shopify Debut 主题,我想以某种方式将增值税 (7%) 添加到变体的价格中。

静态价格我可以开始工作,但是当更改具有不同价格的变体时,hQuery 会覆盖它,我不知道如何通过 jQuery 更改它。

这是来自 theme.js 的 jQuery 片段

/**
 * Trigger event when variant price changes.
 *
 * @param  {object} variant - Currently selected variant
 * @return {event} variantPriceChange
 */
_updatePrice: function(variant) {
  if (
    variant.price === this.currentvariant.price &&
    variant.compare_at_price === this.currentvariant.compare_at_price
  ) {
    return;
  }

  this.$container.trigger({
    type: 'variantPriceChange',variant: variant
  });
},

对于主题模板中的单一价格更改,我使用了此代码段,它可以工作但不适合 jQuery。

  {{  compare_at_price | times:1.07 | money }} 

theme.js 的完整源文件

enter image description here

解决方法

同liquid,但在JS中,找到这些行:

  // On sale
  if (variant.compare_at_price > variant.price) {
    $regularPrice.html(
      theme.Currency.formatMoney(
        variant.compare_at_price,theme.moneyFormat
      )
    );
    $salePrice.html(
      theme.Currency.formatMoney(variant.price,theme.moneyFormat)
    );
    $priceContainer.addClass(this.classes.productOnSale);
  } else {
    // Regular price
    $regularPrice.html(
      theme.Currency.formatMoney(variant.price,theme.moneyFormat)
    );
  }

用这个添加替换它们:

// On sale
  if (variant.compare_at_price > variant.price) {
    $regularPrice.html(
      theme.Currency.formatMoney(
        variant.compare_at_price * 1.07,theme.moneyFormat
      )
    );
    $salePrice.html(
      theme.Currency.formatMoney(variant.price * 1.07,theme.moneyFormat)
    );
    $priceContainer.addClass(this.classes.productOnSale);
  } else {
    // Regular price
    $regularPrice.html(
      theme.Currency.formatMoney(variant.price * 1.07,theme.moneyFormat)
    );
  }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。