0

With Magento 1.7.0.2 If you are on catalog search page and list mode is on.

Url:  http://127.0.0.1/magento_test/catalogsearch/result/index/?mode=list&q=camera

And redirect to current page after adding product to cart is Active in admin panel.

If you try to add simple product to cart, product added to cart successful but redirection URL is not decoded properly

All ‘&’ replaced by ‘&’ and result in breaking search result...

Result URL: http://127.0.0.1/magento_test/catalogsearch/result/index/?mode=list&q=camera

I know this file is responsible, In this fle app\code\core\Mage\Core\Helper\Abstract.php public function escapeUrl($data)

It use htmlspecialchars function of php which replace & with &

So if there is any solution for this, can it safe to remove htmlspecialchars from this function?

This bug is resolved or not?

For what I do now to fix this issue is I have ovewrite my Cartcontroller _goBack function which call this->getResponse()->setRedirect($returnUrl); so for now I have put my custom url redirect.

1

Add this observer to your config.xml:

    <events>
        <checkout_cart_add_product_complete>
            <observers>
                <unique_observer_node>
                    <type>singleton</type>
                    <class>My_Module_Model_Observer</class>
                    <method>checkoutCartAddProductComplete</method>
                </unique_observer_node>
            </observers>
        </checkout_cart_add_product_complete>
    </events>

/app/code/community/My/Modul/Model/Observer.php

function checkoutCartAddProductComplete($observer)
    {
        /**
         * @var $request Mage_Core_Controller_Request_Http
         */
        if (!Mage::getStoreConfig('checkout/cart/redirect_to_cart')) {
            $request     = $observer->getEvent()->getRequest();
            $referrerUrl = $request->getServer('HTTP_REFERER');
            if ($url = $request->getParam(Mage_Core_Controller_Varien_Action::PARAM_NAME_REFERER_URL)) {
                $referrerUrl = $url;
            }
            if ($url = $request->getParam(Mage_Core_Controller_Varien_Action::PARAM_NAME_BASE64_URL)) {
                $referrerUrl = Mage::helper('core')->urlDecode($url);
            }
            if ($url = $request->getParam(Mage_Core_Controller_Varien_Action::PARAM_NAME_URL_ENCODED)) {
                $referrerUrl = Mage::helper('core')->urlDecode($url);
            }
            if (!$this->_isUrlInternal($referrerUrl)) {
                $referrerUrl = Mage::app()->getStore()->getBaseUrl();
            }
            $request->setParam('return_url', $referrerUrl);
        }
    }

    protected function _isUrlInternal($url)
    {
        if (strpos($url, 'http') !== false) {
            if ((strpos($url, Mage::app()->getStore()->getBaseUrl()) === 0)
                || (strpos($url, Mage::app()->getStore()->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, true)) === 0)
            ) {
                return true;
            }
        }
        return false;
    }
| improve this answer | |
  • I know the solution but I am asking if this bug was known? or it was resolved or not? – Mufaddal Jun 6 '13 at 4:18
  • So if there is any solution for this, can it safe to remove htmlspecialchars from this function? I gave solution without rewrite controller – mageUz Jun 6 '13 at 4:53

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.