How to override/extend controller in Magento 1
- Digital Engineering
- Ecommerce
- General
How to override/extend controller in Magento 1
If we want to override controller file in magento 1 then we need to add create custom modules like following:
Create a new module and declare it in “app/etc/modules” by adding a xml file.
app/code/modules/Wd_Wishlist.xml:
1 2 3 4 5 6 7 8 9 |
<?xml version="1.0"?> <config> <modules> <Wd_Wishlist> <active>true</active> <codePool>local</codePool> </Wd_Wishlist> </modules> </config> |
Create folders in app/code/local according to your module and create config.xml in etc folder of your module.
app/code/local/Wd/Wishlist/etc/config.xml:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<?xml version="1.0"?> <config> <modules> <Wd_Wishlist> <version>0.0.1</version> </Wd_Wishlist> </modules> <frontend> <routers> <wishlist> <args> <modules> <Wd_Wishlist before="Mage_Wishlist">Wd_Wishlist</Wd_Wishlist> </modules> </args> </wishlist> </routers> </frontend> </config> |
Create your controller file in “app/code/local/your_module/controllers/”
1 2 3 4 5 6 7 8 9 10 |
app/code/local/Wd/Wishlist/controllers/Index.Controller <?php require_once(Mage::getModuleDir('controllers','Mage_Wishlist').DS.'IndexController.php'); //your previous controller path class Wd_Wishlist_IndexController extends Mage_Wishlist_IndexController { Your code.. } |
We can directly override Model, Block classes by creating file at same path in local folder.
Related content
Auriga: Leveling Up for Enterprise Growth!
Auriga’s journey began in 2010 crafting products for India’s