What is the use of Controller overriding in Magento? - magento

In magento what is the use of overriding a controller?? In java, it can be helpful to call the super class method to the sub class. So is both the overridings are same?? If so, when and where we will override the controller? I knew that magento itself provides modules at app/code/core/Mage path. So instead of this at what situations we will over ride the controllers?
I searched for the google and it shows how to override a controller and I havent find about why to override a controller in magento?
Can anyone explain me about this??

Overriding Controller it mean we can override the Magento Core Controller(app/code/core/Mage/) into Our Custom Magento Module(app/code/local/).
you can implement your custom operations While Overriding Magento Core Controller in custom modules.
Below are the reference for Magento Controller Overriding
https://stackoverflow.com/questions/6980026/override-magento-controller
Magento override controller

Adding to the answer given by #Man kingdom
Overriding a controller avoids messing or playing with core files which magento does not likes.
Even you're overridden controller is false you have a option left to recover from default core files.
Moreover overriding a controller helps you a lot when you want to upgrade your magento version.
Following url's I always refer:
Link 1
Link 2
Hopes this helps you.

Related

How to overload magento CartController

Im trying to overload my CartCotroller so create folder structure like my CartController in the local:
app/code/local/Mage/Checkout/controllers/CartController.php
My question is, does magento execute this Controller and ignore the one whose in the core?
Cause what im trying to do is, i want to add an condition when the customer post a coupon code without changing my form method value. Is it possible?
Yes, Magento will execute the controller placed in app/code/local instead of the core file. An even better way to implement new code or extend the core is to create your own module. So you'd have all your custom code in one place and it's maintanable should you update Magento.
Smashing Magazine gives a nice basic roundup on how to accomplish this. http://coding.smashingmagazine.com/2012/03/01/basics-creating-magento-module/

Overriding Joomla core component file

I am trying to override the com_content/views/article/view.html.php file in joomla using the instructions given in this page
It says I have to create a folder named 'code' in base directory and create the same directory structure. I tried it , but its not working. Can someone confirm whether its working.
Where should I create code folder? Is it on root of joomla installations?
PS- The edit is working correctly when applied on core file
You can override (nearly) any class in Joomla, if your class with the same name is loaded first. To ensure that, you need to create a system plugin.
Here is an example for root/components/com_content/views/article/view.html.php:
class plgSystemOverride extends JPlugin
{
public function onAfterRoute()
{
JLoader::register('ContentViewArticle', 'path/to/override.php', true);
}
}
CAVEAT: Overriding a core class can lead to problems with other extensions, if you're not very careful. For views, though, any interferrence with other extensions is less likely.
You can't override component controllers, models and views in core Joomla! without using a 3rd party plugin.
The plugin you need can be found here: http://extensions.joomla.org/extensions/style-a-design/templating/15611
The code folder then goes into your Joomla root unless you're overriding a back-end view in which case it goes into /administrator
Hope this helps :)
You can use the Class Overrider Plugin http://extensions.joomla.org/extensions/tools/development-tools/23994
just adding some simple human reading commands

Magento - First class / method

I would like to add a registry item at the very start of the all the front-end (and maybe admin) page calls (any kind catalogue, cms, controllers, etc). I want to add:
$myRegistry = new stdClass();
Mage::register('myRegistry',$myRegistry);
Which is the best class / method to overriding?
Ie which class / method is executed for every front-end call (and possibly admin too)?
You can create an observer for the controller_action_predispatch event, that will run before any page is built.
If you need help creating an observer, you can find information on that here: http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/customizing_magento_using_event-observer_method

Work with the cart in the billing.phtml

inside the checkout onepage billing.phtml I have to do several checks and even remove or add stuff to the cart.
But I don't seem to find how to do that
how can I change the cart from within an template?
Thanks,
Joe
I would recommend that you don't apply these logic changes in the phtml. You should try to work with the Shipping or Payment method PHP code, either by extending Magento's core methods or writing your own. There are numerous tutorials on the Magento wiki or other blogs on how to achieve this.
By editing the phtml directly, you run the risk of breaking when Magento releases patches or upgrades, and it is bad practice in general.
From that file you can use $this->getQuote() to get a Mage_Sales_Model_Quote object. Methods you might find useful on that object are getAllItems(), addItem() and removeItem().

Magento - local controller is not working

I have a question regarding Magento's local directory.
I am trying to override a core controller - Mage/Contacts/controllers/IndexController.php.
So I copied IndexController.php to /app/local/Mage/Contacts/controllers/
but Magento is still using core file. I can confirm it because I see 404 page when I rename Mage/Contacts/controllers/IndexController.php to IndexController.php_.
Please advise me.
Thanks!
Copying a controller into the app/code/local path doesn't work unfortunately due to Magento's autoload architecture. It does work with Blocks, Models and other objects, but not controllers.
There is a detailed walkthrough of how to override a controller on the wiki. And a blog post by #prattski
Try following those, then come back with any specific questions.
HTH,
JD

Resources