Jump to content

Disable add to cart when quantity is updating


Joey

Recommended Posts

Hi there,

We are trying to use the following custom js to disable add to cart when the product quantity on the product page is changed:

prestashop.on('updateProduct', function(){ $(".add-to-cart").attr("disabled", true); }); 
if ($product.update_quantity_url <= $product.quantity){
prestashop.on('updatedProduct', function(){ $(".add-to-cart").attr("disabled", false); });

}

 

This works fine on the product page.  Were trying to avoid people adding more to their cart than is available

 

The issue arises on the category listing page... once someone clicks "Add to cart" on any product ALL other product add to cart buttons are disabled.  I assume on the category page that the updateProduct event is triggered when add to cart is clicked but the updatedProduct event is not. Does anyone have any suggestions on how to get around this? 

 

The bottom line is that we just want to avoid people adding more to their cart than is available on the product page.  Thanks

Link to comment
Share on other sites

We discovered the page name attribute... cool.  We solved our issue with the following code in the custom.js... we don't know if this is best practice, so if you think there's a better solution, let us know!

 

if (prestashop.page.page_name == 'product') {
prestashop.on('updateProduct', function(){ $(".add-to-cart").attr("disabled", true); }); 
   if ($product.update_quantity_url <= $product.quantity){
   prestashop.on('updatedProduct', function(){ $(".add-to-cart").attr("disabled", false); });
   }
   
}

Link to comment
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
×
×
  • Create New...