Post by andrejuseu » Sun Aug 26, 2012 3:08 am

Hello,

So I'm trying to make multi qty adding to cart in category page, I made it so far till single adding:
Image
Url: http://i.imgur.com/KeJSt.jpg

And what I want to do:
Image
Url: http://i.imgur.com/30RK4.jpg

Input code:

Code: Select all

<input type="text" size="3" name="quantity<?php echo $product['product_id']; ?>" value="1" />
AddToCart code:

Code: Select all

<input type="button" value="<?php echo $button_cart; ?>" onclick="addToCart('<?php echo $product['product_id']; ?>');" class="button" />
JS part:

Code: Select all

function addToCart(product_id, quantity) {
	quantity = typeof(quantity) != 'undefined' ? quantity : 1;

	$.ajax({
		url: 'index.php?route=checkout/cart/add',
		type: 'post',
		data: 'product_id=' + product_id + '&quantity=' + $('input[name="quantity' + product_id + '"]').val(),
		dataType: 'json',
		success: function(json) {
			$('.success, .warning, .attention, .information, .error').remove();
			
			if (json['redirect']) {
				location = json['redirect'];
			}
			
			if (json['success']) {
				$('#notification').html('<div class="success" style="display: none;">' + json['success'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');
				
				$('.success').fadeIn('slow');
				
				$('#cart-total').html(json['total']);
				
				$('html, body').animate({ scrollTop: 0 }, 'slow'); 
			}	
		}
	});
}
Any suggestions?

CART.lt - custom opencart development, import and export systems, migrations to opencart


User avatar
New member

Posts

Joined
Fri Dec 23, 2011 7:36 pm
Who is online

Users browsing this forum: No registered users and 21 guests