我想在Shopify的Quickview功能中添加基本价格,但是我无法使用jquery正确处理所有问题。我想根据productPrice计算basePase。问题是,该计算未在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>
答案 0 :(得分:0)
您应该能够:
$('.base-price').text(basePrice);
这将找到具有类名'base-price
'的元素,并将文本设置为basePrice
的值。