I know that there is a way to add products to cart by calling cart controller through ajax request. Like:-
$.ajax({
type: "POST",
url: baseUri + '?rand=' + new Date().getTime(),
data: 'controller=cart&add=1&ajax=true&qty=' + $('#quantity_wanted').val() + '&id_product=' + id_product + '&token=' + static_token + ( (parseInt(idCombination) && idCombination != null) ? '&ipa=' + parseInt(idCombination): ''),
beforeSend: function() {
},
success: function() {
}
});
But if I want to do the same thing from a contoller directly without rendering/loading any tpl or js file.
Is there any way to perform the same?
I finally found a way to perform the same.
To add products to cart from a controller directly you have to use the following code.
You can also add a cart rule to the cart directly just by using the id of that cart rule.