Update price automatically when quantity changed on product page Magento

前端 未结 4 2100
眼角桃花
眼角桃花 2020-12-20 05:21

I am looking to have the product price automatically updated based on the quantity the customer has chosen.

Currently when you choose a custom option in magento the

4条回答
  •  长情又很酷
    2020-12-20 05:57

    In Magento 1.9.2.4, the code file to edit is js/varien/product.js

    In Magento 1.9.3 and above, the file to edit is js/varien/product_options.js

    Add the following code:

    var qty;
    if($('qty').getValue().length == 0 || isNaN($('qty').getValue()) || $('qty').getValue() <= 0) { 
        qty = 1;
    } else { 
        qty = $('qty').getValue();
        price *= qty;
    }
    

    right after

    if (price < 0) price = 0;
    

    and before

    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();
        });
    });
    

    Source: https://magentojai.blogspot.com/2015/06/price-update-while-change-qty-in.html

提交回复
热议问题