Magento 2.3 : Load new custom items into Shopping Cart when an button is clicked

by felix   Last Updated August 14, 2019 07:09 AM

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) and then I want to load this products into the cart. This is were I have the problem. I also want that the Mini-enter code herecart gets updated. Is there a way to do this?

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(){
                type:"GET", //First change type to method here
                headers: {
                  'X-Requested-With':  'XMLHttpRequest',
                  'Accept': '*/*',
                contentType: "application/json; charset=utf-8",
                    "_customerID": 1, //for tests
                success:function(response) {
                  alert("An Error occurred. Try again later");

This Ajax is in my view/frontend/templates/button_getcart.phtml file.

Related Questions

Updated April 17, 2018 11:09 AM

Updated December 29, 2018 12:09 PM

Updated July 02, 2019 08:09 AM

Updated August 22, 2017 10:09 AM