gpt4 book ai didi

Magento——根据数量/分级定价动态显示价格

转载 作者:行者123 更新时间:2023-12-02 14:34:17 24 4
gpt4 key购买 nike

最近有几个人问我这个问题,我没有给他们太多答案,而且在其他地方也找不到太多关于这个问题的信息。

默认情况下,在产品页面上显示的价格会根据自定义选项动态更新。根据分级定价结构动态更新价格是否会是一个很大的痛苦?基本上,如果用户使用分级定价的产品,并且输入符合分级定价条件的数量,则价格会根据所选的分级定价和数量进行更新。

我认为一些 jQuery voodoo 应该不会那么难构建,因此价格是根据值重新计算的,但我很好奇是否有其他人以前这样做过,以及他们是否意识到这样做有任何潜在的陷阱这。

是否有充分的理由这样做...或者换句话说,是否有充分的理由为什么不将其构建为 Magento 核心的一部分?

最佳答案

是的,你可以用javascript做到这一点,你只需要将层数据放入<script>内的某个var中即可。在你的模板中,类似这样的东西可以工作(如果你想使用 jQuery):

模板:目录\产品\view.phtml

<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 echo json_encode($_product->getTierPrice()) ?>;
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 updatePrice = function(price){
$('.price').html(price);
};
// you can use more events here if you want a live response while the user is typing
$('#qty').change(function(){
var price = getPrice(this.value);
if(price !== null){
updatePrice(price);
}
});
});
</script>

关于Magento——根据数量/分级定价动态显示价格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12647770/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com