Shopify增值税价格不变

时间:2018-07-06 11:29:24

标签: shopify shopify-template

我正在Shopify上使用波尔图主题。

该网站上的产品价格为exVAT,我已经成功使用以下方法实现了incVat价格:{{variant_tmp.price |时间:1.2 |金钱}}。

但是选择变种时增值税价格不会改变吗?

这是价格框摘要。

<div class="product-type-data">
  <div class="price-box">
    <div id="price" class="detail-price" itemprop="price">
      {% if variant_tmp.compare_at_price > variant_tmp.price %}
      <s class="old-price"> {{ variant_tmp.compare_at_price | money }}</s>
      <!--span class="price_percentage">-{{ variant_tmp.compare_at_price | minus: variant_tmp.price | times: 100.0 | divided_by: variant_tmp.compare_at_price | money_without_currency | times: 100 | remove: '.0'}}%</span-->
      {% endif %}
      <div class="price">{{ variant_tmp.price | money }}</div>
    </div>
    <meta itemprop="priceCurrency" content="{{ shop.currency }}" /> {% if product.available %}
    <link itemprop="availability" href="http://schema.org/InStock" /> {% else %}
    <link itemprop="availability" href="http://schema.org/OutOfStock" /> {% endif %} {% if variant_tmp.price %}
    <div class="price inc-vat">
      <p class="inc-vat">{{ variant_tmp.price | times: 1.2 | money }} inc. VAT </p>
    </div>
    {% endif %}
  </div>
</div>

这是模板底部的JS:

<script>
      productsObj.id{{product.id}} = {{product | json}};
      $(document).ready(function() {
        {% if settings.move_product_tab != blank %}
        $(".product-shop .middle-product-detail").before($(".product-tabs"));
        $(".product-shop .middle-product-detail").before($(".product-tab-accordion")); 
        {% endif %}
      });
      selectCallback = function(variant, selector) {
        if (variant) {
          if (variant.compare_at_price > variant.price) { 
            $("#price").html('<del class="price_compare">' + Shopify.formatMoney(variant.compare_at_price, money_format) + "</del>" + '<div class="price">' + Shopify.formatMoney(variant.price, money_format) + "</div>")
          } else {
            $("#price").html('<div class="price">' + Shopify.formatMoney(variant.price, money_format) + "</div>");
          }
          if (variant.available) {
            frontendData.enableCurrency && currenciesCallbackSpecial("#price span.money"), 
              $(".product-page-area .product-shop .add-to-cart").removeClass("disabled").removeAttr("disabled").html(window.inventory_text.add_to_cart), 
              variant.inventory_management && variant.inventory_quantity <= 0 ? ($("#selected-variant").html(selector.product.title + " - " + variant.title), $("#backorder").removeClass("hidden")) : $("#backorder").addClass("hidden");
            if (variant.inventory_management!=null) {
              $(".product-inventory span.in-stock").text(window.inventory_text.in_stock);
            } else {
              $(".product-inventory span.in-stock").text(window.inventory_text.many_in_stock);
            }
            $('.product-sku span.sku').text(variant.sku);
          }else{
            $("#backorder").addClass("hidden"), $(".product-page-area .add-to-cart").html(window.inventory_text.sold_out).addClass("disabled").attr("disabled", "disabled");
            $(".product-inventory span.in-stock").text(window.inventory_text.out_of_stock);
            $('.product-sku span.sku').empty();
          }
          if( swatch_color_type == '1' || swatch_color_type == '2' ){ 
            var form = $('#' + selector.domIdPrefix).closest('form');
            for (var i=0,length=variant.options.length; i<length; i++) {
              var radioButton = form.find('.swatch[data-option-index="' + i + '"] :radio[value="' + variant.options[i] +'"]');
              if (radioButton.size()) { 
                radioButton.get(0).checked = true;
              }
            } 
          }  
        } 
        if (variant && variant.featured_image) {
          var n = Shopify.Image.removeProtocol(variant.featured_image.src);   
          $(".product-image-thumbs .thumb-link").filter('[data-zoom-image="' + n + '"]').trigger("mouseenter"); 
        }
        variant && variant.sku ? $("#sku").removeClass("hidden").find("span").html(variant.sku) : $("#sku").addClass("hidden").find("span").html("");
      };
      convertToSlug= function(e) { 
        return e.toLowerCase().replace(/[^a-z0-9 -]/g, "").replace(/\s+/g, "-").replace(/-+/g, "-")
      };
      jQuery(function($) {
        {% if product.available and product.variants.size >= 1 %} 
        var product = {{product | json}};
        var layout = $('.product-page-area'); 
        if (product.variants.length >= 1) { //multiple variants
          for (var i = 0; i < product.variants.length; i++) {
            var variant = product.variants[i];
            var option = '<option value="' + variant.id + '">' + variant.title + '</option>'; 
            layout.find('form.product-form > select').append(option);
          }
          new Shopify.OptionSelectors("product-selectors", {
            product: product,
            onVariantSelected: selectCallback, 
            enableHistoryState: true
          });

          //start of quickview variant;
          var filePath = asset_url.substring(0, asset_url.lastIndexOf('/'));
          var assetUrl = asset_url.substring(0, asset_url.lastIndexOf('/'));
          var options = ""; 
          for (var i = 0; i < product.options.length; i++) {
            options += '<div class="swatch clearfix" data-option-index="' + i + '">';
            options += '<div class="header">' + product.options[i] + '</div>';
            var is_color = false;
            var is_square = 'square';
            if (/Color|Colour/i.test(product.options[i])) {
              is_color = true;
            } 
            if (swatch_color_type == '2') {
              is_color = false;
              is_square = '';
            } 
            var optionValues = new Array();
            for (var j = 0; j < product.variants.length; j++) {
              var variant = product.variants[j];
              var value = variant.options[i];
              if(variant.featured_image && product_swatch_setting == '2'){ 
                var img = variant.featured_image.src.lastIndexOf("."); 
                var vimg = variant.featured_image.src.slice(0, img) + "_50x50_crop_center" + variant.featured_image.src.slice(img); 
              }  
              var valueHandle = convertToSlug(value);
              var forText = 'swatch-' + i + '-' + valueHandle; 
              if (optionValues.indexOf(value) < 0) {
                //not yet inserted
                options += '<div data-value="' + value + '" class="swatch-element '+is_square+' '+product_swatch_size+' '+(is_color ? "color" : "")+' ' + (is_color ? "color" : "") + valueHandle + (variant.available ? ' available ' : ' soldout ') + '">';

                if (is_color) {
                  options += '<div class="tooltip">' + value + '</div>';
                }
                options += '<input id="' + forText + '" type="radio" name="option-' + i + '" value="' + value + '" ' + (j == 0 ? ' checked ' : '') + (variant.available ? '' : ' disabled') + ' />';

                if (is_color) {
                  if(vimg && product_swatch_setting == '2'){ 
                    options += '<label for="' + forText + '" class="swatch-image" style="overflow:hidden;"><img src="' + vimg + '" class="variant-image" style="max-width:100%;" /><img class="crossed-out" src="' + assetUrl + 'soldout.png" /></label>';
                  }else{
                    options += '<label for="' + forText + '" style="background-color: ' + valueHandle + '; background-image: url(' + filePath + valueHandle + '.png)"><img class="crossed-out" src="' + assetUrl + 'soldout.png" /></label>';
                  }
                } else {
                  options += '<label for="' + forText + '">' + value + '<img class="crossed-out" src="' + assetUrl + 'soldout.png" /></label>';
                }
                options += '</div>';
                if (variant.available) {
                  $('.product-page-area .swatch[data-option-index="' + i + '"] .' + valueHandle).removeClass('soldout').addClass('available').find(':radio').removeAttr('disabled');
                }
                optionValues.push(value);
              }
            }
            options += '</div>';
          }  
          if(swatch_color_type == '1' || swatch_color_type == '2'){ 
            layout.find('form.product-form .product-options > select').after(options);
            layout.find('.swatch :radio').change(function() {
              var optionIndex = $(this).closest('.swatch').attr('data-option-index');
              var optionValue = $(this).val(); 
              $(this)
              .closest('form')
              .find('.single-option-selector')
              .eq(optionIndex)
              .val(optionValue)
              .trigger('change');
            }); 
          } 

          if (product.available) {
            Shopify.optionsMap = {};
            Shopify.linkOptionSelectors(product);
          }
          //end of quickview variant
        } else { //single variant
          layout.find('form.product-form .product-options > select').remove();
          var variant_field = '<input type="hidden" name="id" value="' + product.variants[0].id + '">';
          layout.find('form.product-form').append(variant_field);
        }
        {% endif %} 
      });
    </script>

非常感谢您的帮助。

0 个答案:

没有答案