4

I want to redirect the page when i am clicking add to cart button

For ex :

product_Name : Product1

Redirect_url : www.somedomain.com...\Product1 (other site url not mine)

product_Name : Product2

Redirect_url : www.somedomain.com...\Product2 (other site url not mine)

when I am clicking add to cart button just to redirect www.somedomain.com\...\Product1 .. \product... not to redirect checkout/cart/page

3 Answers 3

2

There is an option on the add to cart from to submit submit_route_data which will override the standard add to cart url used in Magento.

public function getSubmitUrl($product, $additional = array())
{
    $submitRouteData = $this->getData('submit_route_data');
    if ($submitRouteData) {
        $route = $submitRouteData['route'];
        $params = isset($submitRouteData['params']) ? $submitRouteData['params'] : array();
        $submitUrl = $this->getUrl($route, array_merge($params, $additional));
    } else {
        $submitUrl = $this->getAddToCartUrl($product, $additional);
    }
    return $submitUrl;
}

I have not used this myself but this should work at least for internal urls. An example can be found at app/code/core/Mage/Checkout/Block/Cart/Item/Configure.php in the function _prepareLayout.

For external urls you may need to work with the event controller_action_(pre|post)dispatch_{{fullActionName}} here you should be able to catch the pre dispatch for the add to cart action and then simply redirect the user when the product being added matches a certain product.

1
  • Thank You sir for your idea i will try... thanks a lot @DavidManners
    – Mild Milly
    Commented Apr 28, 2015 at 10:31
1

Please update from

System -> Configuration -> Checkout -> Shopping Cart -> Set After Adding a Product Redirect to Shopping Cart = Yes

Check below screenshot.

enter image description here

1

Go to app/code/core/Mage/Checkout/controllers/CartController.php

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');//enter url to redirect page
        }
        return $this;
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.