这个版本需要的产品选择和第一梯队价格的考虑:
<script type="text/javascript">
jQuery(function($){
// probably you want a custom method in your block for getting a better and safer tierPrices array here
// for example with formatted prices
var tierPrices = <?php
$_tier_json = json_encode($_product->getTierPrice());
$_tier_json = substr($_tier_json,0,1) . '{"price":"'.$_product->getFinalPrice().'","price_qty":"1"},' . substr($_tier_json,1);
echo $_tier_json;
?>;
var getPrice = function(qty){
qty = Number(qty);
var i = tierPrices.length;
while(i--)
{
if(qty >= tierPrices[i]['price_qty']){
return tierPrices[i]['price'];
}
}
return null;
};
var formatPrice = function(price) {
return '$' + parseFloat(price).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,');
};
var updatePrice = function(price){
// if product has options, use optionsPrice functionality
if (typeof optionsPrice != 'undefined' && typeof optionsPrice.productPrice != 'undefined') {
optionsPrice.productPrice = price;
optionsPrice.reload();
} else {
// or if it is a simple product, change price directly in the html
$(".price-box .price").html(formatPrice(price));
}
};
var updatePriceEvent = function() {
var price = getPrice($('#qty').val());
if(price !== null){
updatePrice(price);
}
};
$('#qty').change(updatePriceEvent);
$('div.qty-changer .qty_inc, div.qty-changer .qty_dec').click(updatePriceEvent);
});
</script>
,如果它是一个可配置的产品,或使用自定义选项的产品,它会根据当前选择的选项调整价格。加上,$ _product-> getTierPrice()返回第二层开始价格,这将显示错误的价格在较低的数量
它的工作..但货币符号丢失.... –
我刚刚'var tierPrices = [] ;'在HTML中。我错过了什么吗? – rybo111