Magento产品页面上的数量更改时自动更新价格 [英] Update price automatically when quantity changed on product page Magento
问题描述
我希望根据客户选择的数量自动更新产品价格.
I am looking to have the product price automatically updated based on the quantity the customer has chosen.
当前,当您在magento中选择自定义选项时,价格会自动更新,但在选择数量时不会自动更新.
Currently when you choose a custom option in magento the price automatically updates but when choosing quantity this does not.
因此,场景是产品价格为10英镑.用户输入3个数量,并自动在产品页面上将价格更新为30英镑,依此类推.
So the scenario would be the product price is £10. User enters 3 quantity and automatically on the product page it updates the price to £30 and so on.
有人知道更新它的简单方法吗?
Does anybody know of a simple way of updating this?
推荐答案
在Magento 1.9.2.4中,要编辑的代码文件是js/varien/product.js
In Magento 1.9.2.4, the code file to edit is js/varien/product.js
在Magento 1.9.3及更高版本中,要编辑的文件为js/varien/product_options.js
In Magento 1.9.3 and above, the file to edit is js/varien/product_options.js
添加以下代码:
var qty;
if($('qty').getValue().length == 0 || isNaN($('qty').getValue()) || $('qty').getValue() <= 0) {
qty = 1;
} else {
qty = $('qty').getValue();
price *= qty;
}
紧接着
if (price < 0) price = 0;
以及
if (price > 0 || this.displayZeroPrice) { ...
然后,在文件末尾添加:
And, at the end of the file add:
Event.observe(window, 'load', function() {
$('qty').observe('blur', function(e){
optionsPrice.reload();
});
});
来源: https: //magentojai.blogspot.com/2015/06/price-update-while-change-qty-in.html
这篇关于Magento产品页面上的数量更改时自动更新价格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!