Jump to content

[PS 1.7] Change product price by quantity


knacky
 Share

Recommended Posts

Hi to all.
I need to know how to use JS for the product detail page.
I would like to change the price when changing quantity.

I would like to use the functions from product.js in Prestashop 1.7.> Version.

I don't need to buy modules for> 49 €.

I think it should be the default  function in Prestashop.

Thank you

Share this post


Link to post
Share on other sites

  • 4 weeks later...
On 5/2/2020 at 5:14 PM, JBW said:

You can listen to "updatedProduct" event

prestashop.on('updatedProduct', function() {alert("Updated")});

 

What's the answer?
You can help more people by putting Custom JavaScript code here.
Thank you

Edited by Guest (see edit history)

Share this post


Link to post
Share on other sites

4 minutes ago, Guest said:

What's the answer?

The posted code it the answer to the given request.

On 4/5/2020 at 9:26 AM, knacky said:

I need to know how to use JS for the product detail page

As this is a developer forum the author should be able to implement whatever logic he need by using the event lister - I agree would be nice to publish it here afterward so that other can benefit from it.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

When I advise someone, I give full and functional codes. I am a programmer myself, but it is impossible to know all the functions without quality documentation. Unfortunately, the documentation for developers is insufficient.

Share this post


Link to post
Share on other sites

The user made a beautiful guide for Prestashop 1.6 User @NemoPS

There is nothing for Prestashop 1.7.

If you can do it, you will be the first 🙂

Share this post


Link to post
Share on other sites

  • 7 months later...
  • 6 months later...

I have this functionality in a custom Javascript.

Like this:

$('#quantity_wanted').change(function(e) {
	var price = $('.current-price span').attr("content");
	var cant = parseFloat($('#quantity_wanted').val());
	if (cant >= '1,00' || cant >= 1 || cant >= '1') {
		var total = '<span class="total-price"><span class="price-value"></span></span>';
		$( ".product-quantity" ).html( total );
		finalPrice = parseFloat(price) * parseFloat(cant);
		$('price-value').html(formatNumber.new((finalPrice.toFixed(2)).replace('.',',')));
	}
});

 

I hope it helps.

Share this post


Link to post
Share on other sites

  • 9 months later...
On 7/13/2021 at 11:00 AM, presta_jsM said:

I have this functionality in a custom Javascript.

Like this:

$('#quantity_wanted').change(function(e) {
	var price = $('.current-price span').attr("content");
	var cant = parseFloat($('#quantity_wanted').val());
	if (cant >= '1,00' || cant >= 1 || cant >= '1') {
		var total = '<span class="total-price"><span class="price-value"></span></span>';
		$( ".product-quantity" ).html( total );
		finalPrice = parseFloat(price) * parseFloat(cant);
		$('price-value').html(formatNumber.new((finalPrice.toFixed(2)).replace('.',',')));
	}
});

 

I hope it helps.

Can I copy and paste to my_theme/custom.js ?

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More