I need to add a product to the cart once the user click a button by using my own function.
The button code:
<input type="button" value="Add to cart" onclick="addItemsToCart(83); " class="button btn-success" id="addToCartButton1"/>
<input type="button" value="Add to cart" onclick="addItemsToCart(84); " class="button btn-success" id="addToCartButton2"/>
addItemsToCartFunction:
function addItemsToCart(option_value_id){
$.ajax({
url: 'index.php?route=checkout/cart/add',
type: 'post',
data: 'product_id=' + 92+ '&quantity=' + 1, //need to change this
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');
}
}
});
}
This is working properly.
But This product has a option called 'custom'.
option details according to the database:
option id: 17
option values ids 83 and 84.
I have passed the option value as a parameter to the function addItemsToCart.
Now I need to pass that option and value to the data section. That means I need to change this line.
data: 'product_id=' + 92+ '&quantity=' + 1,
How to do this?