I need a add to cart URL for add the product to cart by open this URL in any browser. I get the add to cart URL by this:


output of above line is: :,/product/2/form_key/rnDRYdCccnTmYsRN/

When i hit the above URL, product is not add to cart. Empty cart page is appeared.

Any idea, how to solve it?

  • Above URL will not add product to cart. Because it will fail the form key validation. so better way is to add a product with code instead of URL directly. – Dhaval Solanki Nov 10 '17 at 5:13
  • I need to use add to cart URL in custom module. any idea how to get the correct URL? @Magento2Learner – pooja Nov 10 '17 at 5:23
  • the above url should work as form key is added in the url itself, Magento it self uses the same code on product listing. Possible issue can be page content being cached and returning same form key everytime , You can try disable caching for the particular page – Piyush Nov 10 '17 at 5:50
  • @Piyush is there any way to get the different form key for each product. – pooja Nov 10 '17 at 6:06
  • First check the url in different browsers, if you are getting exact same url in both browser then you can try to remove that particular page from cache using similar code in this answer magento.stackexchange.com/a/167418/20064 – Piyush Nov 10 '17 at 6:08

You need to check some magento files how they are generating the add to cart URL. Check


File in that you will get one method getAddToCartUrl() You may use this method to get add to cart URL.


| improve this answer | |

Try to change following;


('<?php echo $this->getAddToCartUrl($_product)')


setLocation('<?php echo Mage::helper('checkout/cart')->getAddUrl($_product)')


remove the onclick="productAddToCartForm.submit(this)" in your phtml file.

| improve this answer | |
  • ok i will try and let you know. @anikesh – pooja Nov 10 '17 at 5:12

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.