0

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:

Mage::helper('checkout/cart')->getAddUrl($simple_product)

output of above line is: :

http://192.168.0.78/pooja/testmagento/index.php/checkout/cart/add/uenc/aHR0cDovLzE5Mi4xNjguMC43OC9wb29qYS90ZXN0bWFnZW50by9pbmRleC5waHAvYWRtaW4vc3lzdGVtX2NvbmZpZy9lZGl0L3NlY3Rpb24vd2VvX3Byb2R1Y3RsaXN0L2tleS80YmI4NDEyZTg0ZWZjOTFhMmU1NWY4ZTkwNmIxOGY4OC8,/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?

7
  • 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. Nov 10, 2017 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, 2017 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, 2017 at 5:50
  • @Piyush is there any way to get the different form key for each product.
    – pooja
    Nov 10, 2017 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, 2017 at 6:08

2 Answers 2

0

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

app/code/core/Mage/Catalog/Block/Product/View.php

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

Thanks.

0
0

Try to change following;

setLocation

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

to

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

or

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

1
  • ok i will try and let you know. @anikesh
    – pooja
    Nov 10, 2017 at 5:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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