8

When I add something from the category to the basket/cart it redirects me to the basket/cart.

After searching I found that I could turn this functionality of in the admin system via

Configuration > Sales | Checkout > After Adding a Product Redirect to Shopping Cart

It now redirects to the Home page. I don't know if this a bug in the redirect?

  • No, thats not the case with default Magento Setup. It works completely fine when added from detail page or listing page. Have you done any modification in code or from which page are you trying to do so? – Dexter Jun 24 '14 at 10:28
  • can you check log files.system.log or exception.log file – Pradeep Sanku Jun 24 '14 at 10:32
  • I am using a 3rd party theme. I have done some modification in the frontend/default/{theme_name}/template/product/list.phtml. The page loads okay when I click on it from the menu. – user9252 Jun 24 '14 at 11:03
  • i have configured this setting so after add to cart click it's redirect me to same page.. – Sarfaraj Sipai Aug 7 '18 at 12:25
8

If you look into the cart controller app/code/core/Mage/Checkout/controllers/CartController.php your will find the function _goBack. This is where the return url is decided by Magento.

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;
}

The section your are looking for is the call to _getRefererUrl this happens when you are not setting the return url as a parameter and not using the default redirect to cart option.

Inside the function _getRefererUrl the referrer url is checked to see if it is an internal url, when it is not internal than the base url is used.

I would suggest that either your referrer url is external or there is something wrong with the check.

Have a look at Mage_Core_Controller_Varien_Action::_isUrlInternal to debug if the url is internal or not.

Problem was that _isUrlInternal was failing because of having the port in the base url

  • I am very new to Magento and never debugged anything before in Magengto. What is the process involved so I can debug this URL – user9252 Jun 24 '14 at 12:40
  • @user9252 there are may ways you could go about doing this, what I would suggest could be the easiest would be simply to add a few var_dumps of variables in the function to see what is going on. – David Manners Jun 24 '14 at 12:51
  • I put a debug call after $returnUrl = $this->getRequest()->getParam('return_url'); and it was blank, any suggestions. – user9252 Jun 24 '14 at 13:30
  • 1
    I am using Bitnami, and using the default settings. The default setting is 192.168.1.20:80/magento. Do I remove the port? – user9252 Jun 24 '14 at 15:07
  • 1
    I have removed the port number :80 from the base url. Flush the cache. It now redirects back to the category list page as planned. – user9252 Jun 24 '14 at 15:18
4

In addition to david-manners answer, you as well may have issues with your web/unsecure/base_url & web/secure/base_url being set correctly without ports - but your actual app vhost (apache/nginx) listening on some port other than 80/443, e.g. when running behind varnish.

This will result in \Mage_Core_Helper_Url::getCurrentUrl, used e.g. for adding the base64 encoded query params - decoded and used by _getRefererUrl having the 'non-default' port as part of the url. (e.g. http://www.domain.com:81/your-url.html)

As a result Mage_Core_Controller_Varien_Action::_isUrlInternal returns false...

For further reference, see
http://erikeng.se/post/magento-behind-varnish.html

A clean and good solution is described in
https://serverfault.com/questions/318151/how-to-set-php-server-port-var-to-80-behind-varnish

1

Try to set your web/unsecure/base_url & web/secure/base_url with 127.0.0.1 in place of localhost. For me it worked.

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.