1

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.

5
  • Cache cleared? Anything in logs?
    – user487772
    Jun 25, 2013 at 20:41
  • yes cache was cleared and no nothing logged, and I'm in debug mode too
    – Quantum
    Jun 25, 2013 at 20:43
  • Is your module under Advanced \ Advanced ?
    – user487772
    Jun 25, 2013 at 20:46
  • @Tim I'm not sure what you mean by Advanced \ Advanced but, if you mean is it running and installed (system/advanced) yes, and everything else in the module is working at this time. Only this new part is not working
    – Quantum
    Jun 25, 2013 at 23:48
  • what I think may be in play is that in the sidebar cart template, which is what I'm looking at for confirmation that it's working, uses $this->getUrl('checkout/cart') so I believe I am not coming at this in the right way?
    – Quantum
    Jun 26, 2013 at 16:29

2 Answers 2

2

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.

2
  • well it should be.. I tracked it back to that class. I was I did a board search and that was one of only a few places and the others didn't seem to have a match for those methods. so your saying it looks right, and should be working
    – Quantum
    Jun 26, 2013 at 2:03
  • Hello, I have edited the question to reflect the idea of coming from the wrong class to overload. Thank you
    – Quantum
    Jun 26, 2013 at 14:57
2

Based on OP update:

For the assertion that your rewrite is or is not working, you need to ensure that you are instantiating the correct class. The following test should suffice:

ini_set('display_errors',true);
error_reporting(E_ALL | E_STRICT);
require 'app/Mage.php';
Mage::setIsDeveloperMode(true);
umask(0);
Mage::app();

echo get_class(
    Mage::helper('checkout/url')
);

Output will be one of the following:

  • Wsu_Centralprocessing_Helper_Cart
  • Mage_Checkout_Helper_Url
  • blank / error message

It looks like what you actually need to rewrite is the block class which is rendering the link so that you may pas in the correct store scope. However, I question the need for such a rewrite, as you should be able to pass in store params to the Mage_Core_Model_Url class.

10
  • please explane what you mean on "you should be able to pass in store params to the Mage_Core_Model_Url class" but as far as putting your sinpet in, I put in in the sidebar cart phtml and just get a 404 oddity even after I added die();. It's aready Mage::setIsDeveloperMode(true); in the index so that is removed. but yeah so I guess it's "•blank / error message"
    – Quantum
    Jun 26, 2013 at 16:48
  • ok did ini_set('display_errors',true); error_reporting(E_ALL | E_STRICT); echo get_class( Mage::helper('checkout/url') ); die(); instead and it's Wsu_Centralprocessing_Helper_Url so I would think I was right the first time here on using the helper url.php file
    – Quantum
    Jun 26, 2013 at 16:49
  • even better, just to be sure I do echo get_class( $this->helper('checkout/url') ); die(); and I still get Wsu_Centralprocessing_Helper_Url
    – Quantum
    Jun 26, 2013 at 16:52
  • Tell me more about "what I think may be in play is that in the sidebar cart template, which is what I'm looking at for confirmation that it's working, uses $this->getUrl('checkout/cart')"
    – benmarks
    Jun 26, 2013 at 17:31
  • the sidebar cart phtml uses uses $this->getUrl('checkout/cart') to get the cart url. Under the scope, $this->helper('checkout/url') Wsu_Centralprocessing_Helper_Url so it didn't fit the thought I was having that maybe it was looking somewhere else for the method. I was basicly thinking that maybe it was coming from Mage_Core_Helper_Url maybe or that I was not getting the overload to happen.. or.. well I was just working it out and throwing ideas out but that doesn't mean that though was right.
    – Quantum
    Jun 26, 2013 at 18:02

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.