Magento: How to Add Product and Coupon to Cart Together

addtocartcoupondiscountquote

What I would like to do is add a product and a coupon to the cart at the same time from a product page.

The reasoning behind this is we are creating a landing page for a specific coupon and want to add both the product and coupon to the cart with only a single click for the user.

Best Answer

Hi Have you tried event checkout_cart_add_product_complete and This event is sending params product cart params and product object to Observer

 Mage::dispatchEvent('checkout_cart_add_product_complete',
array('product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse())
);

That using this event you can add your coupon code

If you want apply coupon from product page then create a input on product page or product add to cart url and send (coupon_code=yourcouponCode).

then you get coupon code at observer using $oberver->getEvent()->getRequest()->getParam('coupon_code')

Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->setCollectShippingRates(true);
Mage::getSingleton('checkout/session')->getQuote())->setCouponCode($couponCode)
->collectTotals()
->save();