2

I was going to put together a tiny extension to enable Template hints under global scope, but got stuck trying to rewrite core/template.

Class rewrites only work for classes instantiated via one of Magento's methods to do so (helper, getModel, getSingleton). For abstract and heavily-extended-from classes you seem to be left with the option of local/Mage overrides.

Two questions:

  1. Is there a smart way to avoid local/Mage overrides at all times?
  2. If there isn't, how do you go about including such overrides in community extensions?
6

1) Any extension which you offer to the community should be under the community code pool.

2) You shouldn't, but you can, and sometimes you must because Demeter has been ignored a lot in Magento 1.

There is almost always a way around the need to override, including the use of Reflection as mentioned by Vinai awhile back.

If there is too much downside to workarounds, you simply must take ownership of the class definition. You can do one of the following, provided that users are made aware:

  1. In the community code pool, provide the modified definition under Mage | Varien | Zend namespace as appropriate. Possible concern would be that end user might have done the same.
  2. As above, but in a new code pool: prepend the new codepool to the bootstrapped include paths using set_include_path(). Drawback: more stat()ing caused by the autoloader, and your include path manipulation will be non-obvious as it is outside of the bootstrap.
  3. If possible, provide the definition yourself before it is loaded from its normal location, e.g. by explicitly include()ing it from a non-standard location under your namespace.

Sound your case-by-case needs out here - someone will have an idea. As for the template path hints in the admin scope, see my answer which doesn't even require PHP.

| improve this answer | |

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.