如何在<span>jQuery中更新(Shopify Quickview功能)



我想在 Shopify 中的概览功能中添加基本价格,但我无法使用 jquery 获得所有正确。我想根据产品价格计算基数。问题是,计算没有显示在 HTML 中。看来,我错过了什么。 还是空的。在另一种情况下(Shopify Liquid Code(,这种修改非常简单。在这里,它似乎更复杂。有人对此有想法/解决方案吗?感谢您的帮助!

Shopify.doNotTriggerClickOnThumb = false; 

var selectCallbackQuickview = function(variant, selector) {
var productItem = jQuery('.quick-view .product-item');
addToCart = productItem.find('.add-to-cart-btn'),
productPrice = productItem.find('.price'),
comparePrice = productItem.find('.compare-price'),
basePrice = productItem.find('.base-price'),
totalPrice = productItem.find('.total-price span');           


// Regardless of stock, update the product price
productPrice.html(Shopify.formatMoney(variant.price, "{{ shop.money_format }}"));

// Also update and show the product's compare price if necessary
if ( variant.compare_at_price > variant.price ) {
comparePrice
.html(Shopify.formatMoney(variant.compare_at_price, "{{ shop.money_format }}"))
.show();
productPrice.addClass('on-sale');
} else {
comparePrice.hide();
productPrice.removeClass('on-sale');
}

BASEPRICE IS CALCULATED HERE:
if ( productPrice > 20 ){
if ( productPrice > 90) {
basePrice = productPrice / 75 / 12 * 100;
}
basePrice = productPrice / 75 / 6 * 100;
else {
basePrice = productPrice / 75 * 100;
}

/*recaculate total price*/
//try pattern one before pattern 2
var regex = /([0-9]+[.|,][0-9]+[.|,][0-9]+)/g;
var unitPriceTextMatch = jQuery('.quick-view .price').text().match(regex);
if (!unitPriceTextMatch) {
regex = /([0-9]+[.|,][0-9]+)/g;
unitPriceTextMatch = jQuery('.quick-view .price').text().match(regex);     
}
if (unitPriceTextMatch) {
var unitPriceText = unitPriceTextMatch[0];     
var unitPrice = unitPriceText.replace(/[.|,]/g,'');
var quantity = parseInt(jQuery('.quick-view input[name=quantity]').val());
var totalPrice = unitPrice * quantity;
var totalPriceText = Shopify.formatMoney(totalPrice, window.money_format);
regex = /([0-9]+[.|,][0-9]+[.|,][0-9]+)/g;     
if (!totalPriceText.match(regex)) {
regex = /([0-9]+[.|,][0-9]+)/g;
} 
totalPriceText = totalPriceText.match(regex)[0];
var regInput = new RegExp(unitPriceText, "g"); 
var totalPriceHtml = jQuery('.quick-view .price').html().replace(regInput ,totalPriceText);
jQuery('.quick-view .total-price span').html(totalPriceHtml);     
}
/*end of price calculation*/
};
<div class="prices">
<span class="compare-price"></span>
<span class="price"></span>
<span class="base-price">BASEPRICE SHOULD BE SEEN HERE</span>
</div>

你应该能够做到:

$('.base-price').text(basePrice);

这将查找类名为 'base-price' 的元素,并将文本设置为basePrice的值。

最新更新