Magento – checkout Helper Url overload not working

helpermagento-1.7overrides

I have a simple need to change all the cart URLs to force it to a store's cart. I have set it up the same way as all the examples out there, but it's not the data, it the URL I'm trying to get to. Here is what I have.

The config.xml

<helpers>
  <centralprocessing>
    <class>Wsu_Centralprocessing_Helper</class>
  </centralprocessing>
  <checkout>
    <rewrite>
        <url>Wsu_Centralprocessing_Helper_Url</url>
    </rewrite>
  </checkout>
</helpers>

And the helper file, app\code\local\Wsu\Centralprocessing\Helper\Url.php

class Wsu_Centralprocessing_Helper_Url extends Mage_Checkout_Helper_Url{
    /**
     * Retrieve shopping cart url
     *
     * @return string
     */
    public function getCartUrl(){
        $storeId = 1;//pick up from setting.. look to later but hard code now
        return Mage::app()->getStore($storeId)->getUrl('checkout/cart');
        return $this->_getUrl('checkout/cart');//old function
    }

    /**
     * Retrieve checkout url
     *
     * @return string
     */
    public function getCheckoutUrl(){
        $storeId = 1;//pick up from setting.. look to later but hard code now
        return Mage::app()->getStore($storeId)->getUrl('checkout/onepage');
        return $this->_getUrl('checkout/onepage');//old function
    }
}

As far as I see it, this should be working but it's not. Any ideas why?
Thank you

UPDATE
As suggested in the post, if the class is being invoked directly i.e. new Mage_Checkout_Helper_Url or if another class is extending it is may fail. So with that in mind a quick test of the only other spot that has the method getCartUrl() which is what I need to get at. The helper file Cart.php (app\code\core\Mage\Checkout\Helper\Cart.php) does have that function in it. It extends Mage_Core_Helper_Url. So I added the helper file in my module app\code\local\Wsu\Centralprocessing\Helper\Cart.php with

class Wsu_Centralprocessing_Helper_Cart extends Mage_Checkout_Helper_Cart{
    /**
     * Retrieve shopping cart url
     *
     * @return string
     */
    public function getCartUrl(){
        $storeId = 1;//pick up from setting.. look to latter but hard code now
        return Mage::app()->getStore($storeId)->getUrl('checkout/cart');
        return $this->_getUrl('checkout/cart');
    }

}

and adjusted the config to match

<helpers>
  <centralprocessing>
    <class>Wsu_Centralprocessing_Helper</class>
  </centralprocessing>
  <checkout>
    <rewrite>
        <url>Wsu_Centralprocessing_Helper_Url</url>
        <cart>Wsu_Centralprocessing_Helper_Cart</cart>
    </rewrite>
  </checkout>
</helpers>

This didn't help, so that doesn't seem to be the path I need I believe.

Best Answer

I'm on my phone so I can't search for you, but you need to determine if the class is being invoked directly i.e. new Mage_Checkout_Helper_Url or if another class is extending it. That's the only way this rewrite won't work.

Related Topic