0

I need to do an add to cart in a Magento2.2 site from an external site using ajax. I am using the following ajax code.

jQuery.ajax({
                url: "http://local.magento.com/test_us_en/checkout/cart/add/",
                type: "POST",
        dataType: 'jsonp',
        data:{
            product: 1,
            form_key:tju8cas1gG61phY6,
            qty:2,
        },
        success: function(data) {            
        console.log(data);
         },
         error: function() {
         }
});

please help me.

  • 1
    is the "external site" another platform (say, cms?) running on the same domain? otherwise you will have huge xss challenges doing it over ajax. – iphigenie Jan 4 '18 at 12:49
0

As you want to Cart from external site.

I want to suggest to you use Magento 2 REST API instead Magento own frontend Cart system.

For your current code, you will get Form_key issue as you have trying to cart from external site

http://devdocs.magento.com/guides/v2.2/rest/list.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.