Post by victor.gatto » Mon Oct 24, 2011 9:14 am

i have tried numerous ways to disable the add to cart button after the first click to prevent my customers adding more than 1 product to their cart and i have failed every time.

Could any php or javascript developers please provide some insight or knowledge on how we can achieve this as it would benefit the opencart community, thankyou.

Active Member

Posts

Joined
Thu Sep 01, 2011 9:14 am

Post by imaginetech » Mon Oct 24, 2011 12:34 pm

This can be done easily with some jQuery. The real problem is that this will be highly confusing to your customers.

I think a more common approach would be to have a little error msg display to the visitor that they can only add one item at a time to the cart. Rather than have buttons disappear or stop functioning.

So you'd be looking to check that the cart is empty before adding anything more to the cart and if not empty display an alert.

Something like this should work:-

Look for this function:-

Code: Select all

$('#button-cart').bind('click', function() {

});
When the click event occurs check that cart total on the page (or make and ajax call or php script, whatever to check the cart value). Drop this is:-

Code: Select all

if ($('#cart_total:contains('0.00')")) {
 // Place current add to cart ajax call in here;
} else {
  $('#notification').html('<div class="warning" style="display: none;">Only one item can be added to cart at a time.<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');
  $('.warning').fadeIn('slow');
}
Untested but should work.

Image
www.opencartstore.com
Get OpenCart Templates and OpenCart Modules.


User avatar
Active Member

Posts

Joined
Fri Sep 04, 2009 12:25 pm
Location - Darwin, Australia

Post by PetracheNicolae » Tue Nov 08, 2011 5:41 am

imaginetech wrote:This can be done easily with some jQuery. The real problem is that this will be highly confusing to your customers.

I think a more common approach would be to have a little error msg display to the visitor that they can only add one item at a time to the cart. Rather than have buttons disappear or stop functioning.

So you'd be looking to check that the cart is empty before adding anything more to the cart and if not empty display an alert.

Something like this should work:-

Look for this function:-

Code: Select all

$('#button-cart').bind('click', function() {

});
When the click event occurs check that cart total on the page (or make and ajax call or php script, whatever to check the cart value). Drop this is:-

Code: Select all

if ($('#cart_total:contains('0.00')")) {
 // Place current add to cart ajax call in here;
} else {
  $('#notification').html('<div class="warning" style="display: none;">Only one item can be added to cart at a time.<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');
  $('.warning').fadeIn('slow');
}
Untested but should work.
hello. do you know how i can stop opencart adding in cart more products than they are in stock? i have 1 pice of a product but any client can add 9999 of that and no error. they get the quantity error when they try to checkout. this is so wrong. they shoud have a message telling quantity requested is not in stock the moment they try to add it to cart

New member

Posts

Joined
Tue May 24, 2011 5:40 am
Who is online

Users browsing this forum: No registered users and 164 guests