$(document).delegate('#button-cart', 'click', function() {
	$.ajax({
		url: 'index.php?route=module/ga_tracking/addtocart',
		async: true,
		type: 'post',
		dataType: 'json',
		data: $('.product-info input[type=\'text\'], .product-info input[type=\'hidden\'], .product-info input[type=\'radio\']:checked, .product-info input[type=\'checkbox\']:checked, .product-info select, .product-info textarea'),
		success: function(json) {
			if (json['script']) {
				$('body').append(json['script']);
			}
		}
	});
});

$(document).delegate("[onclick*='addToCart']", 'click', function() {
	
	let string = $(this).attr('onclick');
	string = string.replace("addToCart(", "");
	string = string.replace(");", "");
	string = string.replace(/'/g, "");
	string = string.replace(/ /g, "");
	
	let data = string.split(",");

	$.ajax({
		url: 'index.php?route=module/ga_tracking/addtocart',
		async: true,
		type: 'post',
		dataType: 'json',
		data: {
			product_id:data[0],
			quantity:data[1],
			product_type:data[2],
			merchant_code:data[3]
		},
		success: function(json) {
			if (json['script']) {
				$('body').append(json['script']);
			}
		}
	});
});

$(document).delegate("[onclick*='addToWishList']", 'click', function() {	
	let string = $(this).attr('onclick');
	string = string.replace("addToWishList(", "");
	string = string.replace(");", "");
	string = string.replace(/'/g, "");
	string = string.replace(/ /g, "");
	
	let data = string.split(",");
	
	var quantity = $("input[name*='quantity']").val() || 1;

	$.ajax({
		url: 'index.php?route=module/ga_tracking/addtowishlist',
		async: true,
		type: 'post',
		dataType: 'json',
		data: {
			product:data[0],
			product_type:data[1],
			merchant_code:data[2],
			quantity:quantity
		},
		success: function(json) {
			if (json['script']) {
				$('body').append(json['script']);
			}
		}
	});
});