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
Related
I have 2 Laravel packages; one for managing an admin panel. And the second one for filling it with useful pages.
Now the first package; let's call it AdminPackage from now on. Has a built in Menu Manager which allows me to register new headers & menu links from outside of the package.
The idea is that in my second package, which adds functionality to the first, can call the AdminPackage::menu()->addHeader() and the AdminPackage::menu()->addLink() methods to add some links to the navigation of the admin panel.
But now comes the problem:
When I call the method in my 2nd package's Service Provider I get the following error:
InvalidArgumentException
Route [route-name] not defined.
I have also tried putting the code directly in the Service I'm binding to the IoC container within my ServiceProvider. But same problem.
I get the error using it in both the boot() and register() method. So the routes have not been fully loaded at this point in time.
How can I solve this problem? I need to wait for the routes to finish loading and call the menu manager methods before the page is rendered and the menu items are displayed.
Thanks in advance!
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/
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.
What I want is simple. Whenever, my customer make a purchase on my website I want him/her to be redirected to "My Account" page.
How can I do that?
I am using Magento 1.4.2
Please explain which files to edit and where to edit with whatever code.
I think that you need to pass through the success controller in order to complete the Order.
For example, the successAction into the OnepageController executes some actions to complete the purchase process.
Maybe you can try with an override to that controller (you'll need to do the same with the multishipping controller if you want to use it) to get the redirect to the new destination.
If you don't want to apply an override you an use an observer for the checkout_onepage_controller_success_action event.
I am using Codeigniter with the HMVC Modular extension and have a backend CMS area for managing website content. I am routing the base URL + "admin" (http://localhost/cms/admin) to controller methods with the prefix "admin_".
e.g. function admin_index() {...}
And here is my routing:
$route['admin/([a-zA-Z]+)/(:any)'] = "$1/admin_$2";
$route['^admin/(:any)(/)?'] = "$1/admin_index";
$route['^admin(/)?'] = "dashboard/admin_index";
$route['admin/logout'] = "login/admin_logout";
With the HMVC it is not routing correctly now. Here is what happens:
URL: http://localhost/cms/admin/faqs
Directory: modules/faqs/controllers/faqs - index method
--
here is where it breaks
--
URL: http://localhost/cms/admin/faqs/categories
Directory: modules/faqs/controllers/faqs - categories method (does not exits)
Desired: modules/faqs/controllers/categories - index method
How can I use HMVC while maintaining the "admin" are of the website?
You are making life a bit too tricky by putting frontend and backend functions in the same controllers. Have a look at my article on how to create an admin structure in CodeIgniter.
I'm working on something similar, and implemented a swapping like you did (3rd option) and it worked fine.
I tried to implement a front controller to handle the admin section, and run modules with HMVC modules::run() and buffer the output as I wish, but then I have faced another issue, you will have to change the URI schemes from / to _ or something else, since you wont be able to send module segments as parameter to your controller because CI relies on "/" for it's routing mechanism.
The only way is to emulate the admin section as Phil suggested, but there is another option to still have control over the code implemented by anyone using your CMS.
You could extend CI_Controller (or MX_Controller in case you are using HMVC) and add an Admin_Controller which will handle your logic and control what modules can do.
Have a look at this CodeIgniter Base Classes: Keeping it DRY