有没有办法将数量选择器乘以产品价格以产生小计价格?

时间:2019-07-22 04:53:49

标签: javascript java jquery ajax shopify

我们正尝试将数量选择器乘以产品价格,以在产品页面上提供小计。

<div class="product-single__price-{{- section.id -}}">
            <div class="price" id="price">
                <span class="amount price-old{%- unless current_variant.compare_at_price &gt; current_variant.price %}{{-" id="ComparePrice-{{- section.id -}}"><span class="money">{%- if current_variant.compare_at_price &gt; current_variant.price -%} {{- current_variant.compare_at_price | money -}} {%- endif -%}</span></span> {%- if current_variant.compare_at_price &gt; current_variant.price -%} <span class="amount price-new" id="ProductPrice-{{- section.id -}}"><span class="money">{{- current_variant.price | money -}}</span></span> {%- else -%} <span class="amount price-new" id="ProductPrice-{{- section.id -}}"><span class="money">{{- current_variant.price | money -}}</span></span> {%- endif -%} <span class="hide" itemprop="price">{{- product.price | money_without_currency -}}</span>
                <meta content="USD" itemprop="priceCurrency">
            </div>
        </div>


        <div class="quantity-wrapper">
            <p>
                {{'products.product.quantity' | t}}
            </p>
            <div class="quantity">
                <input class="quantity-cart-{{product.id}}" id="quantity_wanted" name="quantity" size="2" type="text" value="1"> <a class="q_up" data-product_id="{{product.id}}" href="javascript:void(0);" id="q_up"><i class="fa fa-plus"></i></a> <a class="q_down" data-product_id="{{product.id}}" href="javascript:void(0);" id="q_down"><i class="fa fa-minus"></i></a>
            </div>
        </div>

当前使用的js代码

        < script > jQuery(".quantity").on("click", function() {
            var oldValue = jQuery("#quantity").val(),
                newVal = 1;
            if (jQuery(this).text() == "q_up") {
                newVal = parseInt(oldValue) + 1;
            } else if (oldValue > 1) {
                newVal = parseInt(oldValue) - 1;
            }
            jQuery("#quantity").val(newVal); { %
                if product.available %
            }
            updatePricing(); { % endif %
            }
        }); < /script>

FE上的输出

   <div class="price">
     <label>{{ 'products.general.subtotal_price' | t }}<span>{{ product.price | money }}</span></label>
   </div>

0 个答案:

没有答案