cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamically update price on product page

Dynamically update price on product page

I've been searching high and low for this quite simple solution. I'd like to have the product price automatically update based on the quantity placed by the customer. This should work on simple products as well as with tiered pricing and even in configurable products. Hope you can help me. 

 

Thanks!

7 REPLIES 7

Re: Dynamically update price on product page

I'd like to know how to do this to. I have found several "solutions" online, but for older versions of Magento. The links for these "solutions" are below. Maybe by bumping this, someone will see it. Or someone will look at the older solutions and let us know how/where to do it now.

 

http://stackoverflow.com/questions/20732818/dynamically-automatically-update-price-from-qty-on-your-...

 

http://www.opencartas.com/magento/update-price-when-quantity-qty-is-entered-18467.html

 

http://stackoverflow.com/questions/12647770/magento-display-price-dynamically-based-on-quantity-tier...

Re: Dynamically update price on product page

We have same wish.

We think it would be convenient, if products Detail page showed Price multiplied with just entered amount before clicking the add to cart button

 

i have experimented a while now and have posted several questions  - no answer so far

i tell you how far i am until now

 

https://magento.stackexchange.com/questions/196630/display-javascript-calculated-final-price-with-qu...

 

have you found a solution for this Task?

 

 

Re: Dynamically update price on product page

In case you are looking for more in terms of dynamic pricing, I would suggest you to drop me an email at aayush.agarwal@greendeck.co

 

My company Greendeck helps ecommerce stores with dynamic pricing! 

Re: Dynamically update price on product page

Hi there,

If you may need sth similar but depending on competitor prices, i.e. to apply dynamic & competitive pricing for your products, I might be of help if you drop me an email at burc@prisync.com.

Our company Prisync.com, helps Magento merchants of all sizes from all around the world to set up smart competitive price rules for their products and run dynamic pricing strategy with a self-service platform.

Hope to hear back from you soon!

Cheers,

Burc

Re: Dynamically update price on product page

I see that the Stackexchange post has been removed and no solution here either after nearly two years. It seems this is yet another basic feature that was achievable in Magento 1 (albeit with custom coding) but not in Magento 2. I am only on my second M2 development and I've lost count of the compromises I have had to make because M2, despite its better looks and generally faster performance, simply doesn't seem to have the flexibility of the old platform. Or perhaps it just hasn't been around long enough for developers to have found ways around its many limitations.

Re: Dynamically update price on product page

@webrightnow 

 

Here is how I did it:

 

all of this is in the addtocart.phtml

 

 <div class="qty-wrapper">
                <label for="qty"><?php echo $this->__('Qty:') ?></label>
                <input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" onchange="changeFunction();" onkeyup="this.onchange();" 
                    onpaste="this.onchange();" oninput="this.onchange();" onfocus="this.onchange()" />
</div>
<script>
    function changeFunction() {
        if (hasSpecial.length <= 0) {
            if (!isNaN(document.getElementById("qty").value) && document.getElementById("qty").value!= "") {
                var x = parseFloat(document.getElementById("qty").value);
                if (x < .25) {
                    x = .25;
                }
                var y = document.getElementsByClassName("price");
                var priceString = y[0].innerHTML;
                var originalPrice = parseFloat(priceString.substr(1));
                if (currentPrice != originalPrice && currentPrice != 0) {
                    finalPrice = currentPrice * x;
                }
                else {
                    finalPrice = originalPrice * x;
                }
                y[0].innerHTML = "$" + finalPrice.toFixed(2);
                currentPrice = finalPrice / x;
            }
        }
        else {
            if (!isNaN(document.getElementById("qty").value) && document.getElementById("qty").value!= "") {
                var x = parseFloat(document.getElementById("qty").value);
                if (x < .25) {
                    x = .25;
                }
                var y = document.getElementsByClassName("price");
                var priceString = y[1].innerHTML;
                var originalPrice = parseFloat(priceString.substr(22));
                if (currentPrice != originalPrice && currentPrice != 0) {
                    finalPrice = currentPrice * x;
                }
                else {
                    finalPrice = originalPrice * x;
                }
                y[1].innerHTML = "$" + finalPrice.toFixed(2);
                currentPrice = finalPrice / x;
            }
        }
    }
</script>

I don't know if this is any different for M2 or not, just my solution for M1.

Re: Dynamically update price on product page

After almost 2 years, I am finally getting an M2 site starting and wanted to figure this out. The code I posted will work, just don't forget to initialize "currentPrice" in a separate <script>

 

Also I updated my code to include changing both Regular and Special pricings at the same time

 

<script>
var currentPrice = 0;
var currentSpecial = 0;
</script>

<script>
     function changeFunction() {
            if (!isNaN(document.getElementById("qty").value) && document.getElementById("qty").value!= "") {
                var x = parseFloat(document.getElementById("qty").value);
                if (x < .25) {
                    x = .25;
                }
                var y = document.getElementsByClassName("price");
                var priceString = y[0].innerHTML;
                var specialString = y[1].innerHTML;
                var originalPrice = parseFloat(priceString.substr(1));
                var specialPrice = parseFloat(specialString.substr(1));
                if (currentPrice != originalPrice && currentPrice != 0) {
                    finalPrice = currentPrice * x;
                }
                else {
                    finalPrice = originalPrice * x;
                }
                if (currentSpecial != specialPrice && currentSpecial != 0) {
                    specialFinal = currentSpecial * x;
                }
                else {
                	specialFinal = specialPrice * x;
                }
                y[0].innerHTML = "$" + finalPrice.toFixed(2);
                y[1].innerHTML = "$" + specialFinal.toFixed(2);
                currentPrice = finalPrice / x;
                currentSpecial = specialFinal /x;
            }
        }
</script>

again, all of this is done in addtocart.phtml