Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
619 views
in Technique[技术] by (71.8m points)

javascript - 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.

Currently when you choose a custom option in magento the price automatically updates but when choosing quantity this does not.

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Using jquery you can do this

$('#qty').keyup(function(){
    if($(this).val() != '' && isNumber($(this).val()) && $(this).val() > 0)
    {
       var price = $('#real_price').val() * 1;
       var qty = $(this).val() * 1;
       var total = price * qty;
       $('#price').html(total);
    }
    else
    {
       $('#price').html('500');    
    }
});

function isNumber(n) {
    return !isNaN(parseFloat(n)) && isFinite(n);
}

FIDDLE


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...