Sorry, nothing in cart.
There might be some particular reasons when you have to change the Magento‘s core files then you should be very careful otherwise all your changes made in core files will be lost when the current Magento version is upgraded to latest version. Before changing anything in the core you should device a clear cut policy to ensure that your customized core files are upgradable, non-over writable and easier to accommodate further customizations.
Magento gives the flexibility to customize it’s core but the most important thing is the developers discipline. A slight negligence can make all efforts go in vain especially when the Magento version is upgraded, degraded etc.
Understanding Magento’s Configuration Files
Magento uses merging concept of several files (XML) into one global cached configuration file (XML) just to achieve maximum flexibility of configuration without need for manual editing of configuration files.
Notice how 2 configuration XML files are merged into one global configuration file
Sample 1 (Configuration)
Sample 2 (Configuration)
Data3 Data4 Data5
Merged file contains both the sample configuration files.
Data1 Data3 Data4 Data5
Important Files Used In Magento Configuration
Refer init() method under app/code/core/Mage/Core/Model/Config.php
- If usage of config cache is enabled, Magento will try to load the configuration from cache. If loaded successfully, it will skip all the following steps.
app/etc/config.xml. This file contains values absolutely necessary for successful load of Magento core components.
- Merge all files from
app/etc/modules.xmluntil 0.6.14100). Files containing modules declarations are dropped here by the core, community and custom packages installed, and are named by package name (Mage_All.xml).
app/etc/local.xml. Contains settings for local database connections, installation date and local encryption key.
app/etc/local.xmlwas not found (not installed yet)
app/etc/distro.xmlis merged. Contains auto-configured values to be used in installation wizard.
config.xmlfrom all the modules that were declared in
app/etc/modules/*. These are:
Models are basically set of specific classes to define abstract or resource specific logic. Following code will display how to define a new module functionality:
Now lets create
The above code will enable us to use
$obj = Mage::getModel('example_mod/test_model') and will return an instance of the class
Example_Module_Model_Test_Model, located under
app/code/local/Example/Module/Model/Test/Model.php. Notice how
example_mod is replaced with
Example_Module_Model and together with
test_model generate name of required class.
Further Reading: How to Override Magento’s Core Model Classes
The real beauty lies under customization especially if you are willing to upgrade the code without changing the files manually. Now, if the discipline is followed you can easily override the functionalities without actually changing the core files.
Now, lets take an example where we will try to create a new module In our example we will create a new module called
Example_Custom which will further override the
Example_Module functionality. Defining this new module is same as
To ensure that the application won’t break we will provide all classes in our custom module that exists in our original module.
Now lets override only one class to see how it works
app/code/local/Example/Custom/Model/Test/Model.php will look something like this:
Now, everywhere in the code
$obj = Mage::getModel('example_mod/test_model')will return an instance of
Example_Custom_Model_Test_Modelwith all original functionality of
Helper are the support classes for performing some specific manipulations with data in
*.phtmltemplates or in
*.xmllayouts i.e.$this->helper('wishlist'); // wishlist module; data.php helper $this->helper('catalog/image'); //catalog module; image.php helper $this->helper(); //current module; data.php helper
Helpers are also useful for caching purposes (refer to
Resources are overloaded the same way as we overload models. These are the data persistence resources used by the system’s data mapper. Also business logic for model collections are encapsulated in collection resources. All data access funnels down thru the resources from the models (or controllers, if business logic is being defined in a page controller )
Admin Menu and ACL
Admin menu is setup in
app/code/core/Mage/Adminhtml/etc/config.xmlCopy & paste an existing XML chunk and customize as per your requirements. You can supposedly put this in any other configuration file ( think a user created module ) & have the XML merged in.
Magento Customization How To's
I am still drafting my howto's for customizing Magento. Just, stay tuned for my next post where i will focus on how to customize Blocks, Controllers and Themes.
Please leave me a comment and let me know your own experiences of Overriding the Magento core. Subscribe our RSS to receive latest Magento updates.