Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between override and rewrite in magento

Is both term override and rewrite are same in Magento. I have searched alot for this but not found any answer.

Thanks

like image 567
Pankaj Pareek Avatar asked Jun 14 '13 09:06

Pankaj Pareek


1 Answers

Short answer: yes, though it depends on who you talk to.

All rewrites are overrides, but not all overrides are rewrites. A rewrite in Magento should only refer to a configuration-based class overrides. Factory methods are used by the framework to instantiate the MVC types:

  • Mage_Core_Model_Layout->createBlock()
  • Mage::helper()
  • Mage::getModel()
  • Mage::getResourceModel()
  • etc....

These methods generally match a class group (e.g. catalog) to a class prefix (e.g. Mage_Catalog_Model) in order to instantiate a particular class (e.g. Mage::getModel('catalog/product') yields Mage_Catalog_Model_Product). This mapping allows for developers to specify a certain xpath associated with the class argument (e.g. 'catalog/product' & global/models/catalog/rewrite/product) to specify an alternate class to instantiate. From there it's the responsibility of the developer to use inheritance as appropriate to achieve the proper overriding & extending behavior.

There are other mechanisms for achieving overrides, the most common of which is the so-called "include path hack", which allows for classes from "lower" autoload directories to be (re)defined in higher-level directories in the following order of precedence (note that app/code/local/):

  • app/code/community/
  • app/code/core/
  • lib/

This style of override should be considered a last-case means of changing core code. It has legitimate use cases (especially for obeying DRY), but may be non-obvious in an upgrade.

like image 112
benmarks Avatar answered Sep 20 '22 17:09

benmarks