3

I have a problem modifying a redirect in magento CE 1.9.2.

Let's say a customer has a configurable product in the cart, and would like to edit that product (ie. changing color or size or something).

After changing the options and clicking the 'update cart' button I want the customer to stay on the same page (ie. the edit product page). However magento always redirect back to the cart page.

I think I've found source of the problem, in CartController.php from the Checkout module:

/**
 * Update product configuration for a cart item
 */
public function updateItemOptionsAction()
{
    $cart   = $this->_getCart();
    $id = (int) $this->getRequest()->getParam('id');
    $params = $this->getRequest()->getParams();

    if (!isset($params['options'])) {
        $params['options'] = array();
    }
    try {
        if (isset($params['qty'])) {
            $filter = new Zend_Filter_LocalizedToNormalized(
                array('locale' => Mage::app()->getLocale()->getLocaleCode())
            );
            $params['qty'] = $filter->filter($params['qty']);
        }

        $quoteItem = $cart->getQuote()->getItemById($id);
        if (!$quoteItem) {
            Mage::throwException($this->__('Quote item is not found.'));
        }

        $item = $cart->updateItem($id, new Varien_Object($params));
        if (is_string($item)) {
            Mage::throwException($item);
        }
        if ($item->getHasError()) {
            Mage::throwException($item->getMessage());
        }

        $related = $this->getRequest()->getParam('related_product');
        if (!empty($related)) {
            $cart->addProductsByIds(explode(',', $related));
        }

        $cart->save();

        $this->_getSession()->setCartWasUpdated(true);

        Mage::dispatchEvent('checkout_cart_update_item_complete',
            array('item' => $item, 'request' => $this->getRequest(), 'response' => $this->getResponse())
        );
        if (!$this->_getSession()->getNoCartRedirect(true)) {
            if (!$cart->getQuote()->getHasError()) {
                $message = $this->__('%s was updated in your shopping cart.', Mage::helper('core')->escapeHtml($item->getProduct()->getName()));
                $this->_getSession()->addSuccess($message);
            }
            $this->_goBack();
        }
    } catch (Mage_Core_Exception $e) {
        if ($this->_getSession()->getUseNotice(true)) {
            $this->_getSession()->addNotice($e->getMessage());
        } else {
            $messages = array_unique(explode("\n", $e->getMessage()));
            foreach ($messages as $message) {
                $this->_getSession()->addError($message);
            }
        }

        $url = $this->_getSession()->getRedirectUrl(true);
        if ($url) {
            $this->getResponse()->setRedirect($url);
        } else {
            $this->_redirectReferer(Mage::helper('checkout/cart')->getCartUrl());
        }
    } catch (Exception $e) {
        $this->_getSession()->addException($e, $this->__('Cannot update the item.'));
        Mage::logException($e);
        $this->_goBack();
    }
    $this->_redirect('*/*');
}

The call to $this->_goBack() in the end of the try-block seems to set the redirect URL correctly by looking at settings and a 'return_url' parameter (and I've verified that the code gets this far). But, as you can see, the last line always sets a redirect to */* no matter what. Just adding a return statement after the _goBack() call fixes the problem but I rather do this without modifying the core files.

Any ideas how I can solve this problem?

1
  • You could either override the CartController in a custom module, or find another way around. As far as I know, when you edit a configurable product, it should redirect you to the cart (default behavior) which seems logical because you wanted to change the option, not gaze at the product once more. Why would you want customers to stay on the edit page? Commented Jul 23, 2015 at 14:38

1 Answer 1

0

If you want the customer to say on the update page you could

  1. Use Ajax to post the changes to the server.

  2. Add a return_url parameter to your post action (with the current url see protected function _goBack())

  3. Change the global behavior for adding and updatig product in System -> Configuration -> Sales tab -> Checkout and then in the Shopping Cart tab you set the After Adding a Product Redirect to Shopping Cart

  4. Rewrite the controller using a custom module

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.