I am making my own module and now I added a button into it. If this button is clicked I want to get products with an AJAX request from a REST API (I already get my products, this is no problem).
Afterwards I want to load this products into the cart. This is were I have the main problem. I also want that the minicart gets updated. Is there a way to do this? I am very desperate.
This is my AJAX request (Yes I know that I currently not store the data I get back, I will add this when I have the solution for the problem I mentioned before):
jQuery("#getCart").on("click", function(){
jQuery.ajax({
url:"http://192.168.10.106:8080/api/cart/",
type:"GET", //First change type to method here
headers: {
'X-Requested-With': 'XMLHttpRequest',
'Accept': '*/*',
'Cache-Control':'no-cache',
},
contentType: "application/json; charset=utf-8",
data:
{
"_customerID": 1, //for tests
}
success:function(response) {
},
error:function(){
alert("An Error occurred. Try again later");
}
});
}
});
This AJAX is in my view/frontend/templates/button_getcart.phtml file.
Can someboy please help me? I really need a solution for this and I am new to Magento 2.