magento: URL querystring for adding product and applying discount coupon to cart

rukpat picture rukpat · Nov 5, 2012 · Viewed 7k times · Source

I am a newbie, after extensive research and exploration I am able to figure out the following:

To add a product to cart I can use

/checkout/cart/add?product=76&qty=1

to apply discount code I can use

/checkout/cart/couponPost?coupon_code=WQ9D-XXXX

The code for it resides in file:

/public_html/app/code/local/Mage/Checkout/controllers/-

I would like to add product and apply discount code in one link such as:

/checkout/cart/couponPost?product=76&qty=1&coupon_code=WQ9D-XXXX

OR

/checkout/cart/add?product=76&qty=1&coupon_code=WQ9D-XXXX

OR Any other means?

Is there a way to get this working? Idea is to embed this link in a newsletter so using one click the user is able to add the product to cart and get discount.

I have tried calling $this->couponPostAction(); from function addAction() and vice-versa but it does not work!

Answer

rukpat picture rukpat · Nov 5, 2012

Got it working without modifying the code,

'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 return_url has to be encoded.

Please see: http://www.magentocommerce.com/boards/viewthread/296763/