1

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.

  • How to extend the functionality of this snippet to apply coupon when two products (different IDs) are in the cart? Coupondunia – crazy krush Jan 3 '19 at 6:58
  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review – Aditya Shah Jan 3 '19 at 7:25
1

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();
| improve this answer | |
  • you are welcome @DavidManners – Amit Bera Nov 12 '14 at 9:54
0

You could customize your add to cart button to use the querystring method

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

 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 - need to be encoded

See /app/code/core/Mage/Checkout/controllers/CartController.php

/**
 * Set back redirect url to response
 *
 * @return Mage_Checkout_CartController
 */
protected function _goBack()
{
    $returnUrl = $this->getRequest()->getParam('return_url');
    if ($returnUrl) {

        if (!$this->_isUrlInternal($returnUrl)) {
            throw new Mage_Exception('External urls redirect to "' . $returnUrl . '" denied!');
        }

        $this->_getSession()->getMessages(true);
        $this->getResponse()->setRedirect($returnUrl);
    } elseif (!Mage::getStoreConfig('checkout/cart/redirect_to_cart')
        && !$this->getRequest()->getParam('in_cart')
        && $backUrl = $this->_getRefererUrl()
    ) 
| improve this answer | |
0

Another approach is to look at the SalguaMagentoAddProduct extension https://github.com/salgua/SalguaMagentoAddProduct it provides the ability to do what you are looking for.

| improve this answer | |

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.