Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Add Product and apply Coupon Code in shopping cart from URL querystring
 
rukpat
Jr. Member
 
Total Posts:  4
Joined:  2012-03-11
 

Sometimes it is nice to be able to take user directly to the shopping cart with product and discount coupon applied. e.g. from a email newsletter. There a few extensions out there that does this, they seem unnecessary. Magento out of box provide following:

To add Product:

http://www.example.com/checkout/cart/add?product=76&qty;=1

where 76 is product id and 1 is the quantity.

To apply coupon code:

http://www.example.com/index.php/checkout/cart/couponPost?coupon_code=WQ9D-XXXX

where WQ9D-XXXX is the coupon code.

additional magento also provides parameter for return URL

return_url

.

Bringing it all together in one URL:

http://www.example.com/checkout/cart/add?Product=76&qty;=1&return;_url=http://www.example.com/index.php/checkout/cart/couponPost?coupon_code=WQ9D-XXXX&return;_url=http://www.example.com/checkout/cart/

The first return URL has to be encoded. Use your fav encoder

It works in 1.7.
Useful?

 
Magento Community Magento Community
Magento Community
Magento Community
 
evancelt
Jr. Member
 
Total Posts:  1
Joined:  2013-01-22
 

Thanks so much for your post Rukpat.

I was able to get it working on 1.702 with a few adjustments:
1. Remove the semicolons from your example
2. No need to encode the 2nd link (if you don’t care that users see that a discount has been applied)

Example:

http://www.example.com/checkout/cart/add?Product=76&qty;=1&return;_url=http://www.example.com/index.php/checkout/cart/couponPost?coupon_code=WQ9D-XXXX
 
Magento Community Magento Community
Magento Community
Magento Community
 
sanekjn
Jr. Member
 
Total Posts:  6
Joined:  2013-05-20
 
evancelt - 20 March 2013 07:32 AM

Thanks so much for your post Rukpat.

I was able to get it working on 1.702 with a few adjustments:
1. Remove the semicolons from your example
2. No need to encode the 2nd link (if you don’t care that users see that a discount has been applied)

Example:

http://www.example.com/checkout/cart/add?Product=76&qty;=1&return;_url=http://www.example.com/index.php/checkout/cart/couponPost?coupon_code=WQ9D-XXXX

Could you tell more detailed how to get it work on 1.702?
I get this error

Not Found

The requested URL 
/checkout/cart/add was not found on this server.

the query is

site.com/checkout/cart/add?product=2&qty;=1
 
Magento Community Magento Community
Magento Community
Magento Community
 
sanekjn
Jr. Member
 
Total Posts:  6
Joined:  2013-05-20
 

All I need to do, just add index.php in query

site.com/index.php/checkout/cart/add?product=2&qty;=1
 
Magento Community Magento Community
Magento Community
Magento Community
 
ccontardo
Jr. Member
 
Total Posts:  1
Joined:  2013-04-26
 

Hi,
can i use the return_url querystring with an external site??…

Im getting a “denied” message:

External urls redirect to “http://anotherwebsite.com/xxx/test.html” denied!

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top