0

When I apply a coupon code on cart page and then submit it automatically, the customer is redirected to home page and show success message in home page only.

How to avoid the redirect, stay on the same page and show the success message on the cart page?

<form id="discount-coupon-form" action="<?php echo $this->getUrl('checkout/cart/couponPost') ?>" method="post">
    <div class="discount">
        <div class="discount-form">
           <input type="hidden" name="remove" id="remove-coupone" value="0" />
            <div class="input-box">
                <input class="input-text" id="coupon_code" name="coupon_code" value="<?php echo $this->escapeHtml($this->getCouponCode()) ?>" placeholder="Enter Your Coupen code if you have...." />
            </div>
            <div class="buttons-set">
                <button type="button" title="<?php echo $this->__('Apply Coupon') ?>" class="button" onclick="discountForm.submit(false)" value="<?php echo $this->__('Apply Coupon') ?>"><span><span><?php echo $this->__('Apply Coupon') ?></span></span></button>
                <?php if(strlen($this->getCouponCode())): ?>
                    &nbsp; <button type="button" title="<?php echo $this->__('Cancel Coupon') ?>" class="button" onclick="discountForm.submit(true)" value="<?php echo $this->__('Cancel Coupon') ?>"><span><span><?php echo $this->__('Cancel Coupon') ?></span></span></button>
                <?php endif;?>
            </div>
        </div>
    </div>
</form>
<script type="text/javascript">
//<![CDATA[
var discountForm = new VarienForm('discount-coupon-form');
discountForm.submit = function (isRemove) {
    if (isRemove) {
        $('coupon_code').removeClassName('required-entry');
        $('remove-coupone').value = "1";
    } else {
        $('coupon_code').addClassName('required-entry');
        $('remove-coupone').value = "0";
    }
    return VarienForm.prototype.submit.bind(discountForm)();
}
//]]>
</script>
  • Status messages normally are handled by your page design. Look at app/design/frontend/base/default/template/1column.phtml and find $this->getChildHtml('global_messages'). But even if there is none, your redirect to the homepage is not normal. Can you give more info please. Are you using a commercial template? Please post the complete HTML form-node of the coupon input field. – Nicolas Sep 22 '15 at 6:12
  • check my update question – Magento 2 Sep 22 '15 at 6:45
  • sucess message redirect to homepage – Magento 2 Sep 22 '15 at 6:47
  • @Magento2 May i know what change you did? – zus May 28 '18 at 5:58
2

The problem is the redirect, correct?

The coupon code is processed here: \Mage_Checkout_CartController::couponPostAction, as you can see in your form:

<form ... action="<?php echo $this->getUrl('checkout/cart/couponPost') ?>" ... >

As far as I can see every path ends with \Mage_Checkout_CartController::_goBack

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()
    ) {
        $this->getResponse()->setRedirect($backUrl);
    } else {
        if (($this->getRequest()->getActionName() == 'add') && !$this->getRequest()->getParam('in_cart')) {
            $this->_getSession()->setContinueShoppingUrl($this->_getRefererUrl());
        }
        $this->_redirect('checkout/cart');
    }
    return $this;
}

I neither can see a param return_url, nor in_cart.

So you should be redirected to the cart.

Whatever happens, you have a module which kills this behaviour and we can't help you debug this. Read Fundamentals for debugging a Magento store and turn on your xdebug to check where your code is running.

1

My problem is solved by adding https url, in the action of the form in which my coupon code input field is present.There was http url in the action of the from that was redirecting to http url (unsecure) home page.

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.