abdullacm Posted October 11, 2014 Share Posted October 11, 2014 Hi, I'm developing a module, i want to override or extend productController from the module, what are all the ways doing this other than placing /override/ directory using a module? Link to comment Share on other sites More sharing options...
razaro Posted October 11, 2014 Share Posted October 11, 2014 Well it is connected to what you want to accomplish. Placing file in modules/override/ is one but it is better if you can some hook on product page or module controller. Link to comment Share on other sites More sharing options...
abdullacm Posted October 12, 2014 Author Share Posted October 12, 2014 i need to add some code into postProcess of cartcontroller, how to do this with my module main file? Link to comment Share on other sites More sharing options...
razaro Posted October 12, 2014 Share Posted October 12, 2014 Well for that probably best way is overriding, but again depends what you want to do. Maybe you could add additional tab in product edit in back office that could save some value, that value will be specific to each product. Link to comment Share on other sites More sharing options...
bellini13 Posted October 13, 2014 Share Posted October 13, 2014 postProcess of the Cart Controller does not contain any hooks. But the postProcess function really just executes a bunch of other functions for dealing with add, delete, update of a customer cart. Do you need to do something for all of those events, or only 1 of them. If you really want to do something during postProcess, then create the override file, and in that file you would have a single function that looks like this public function postProcess() { //add your logic here //then execute the parent postProcess here parent::postProcess(); } Note that the above will execute your logic first, and then execute the standard logic second. This is because the parent function will perform a redirect when it is finished, and your code would never execute if you move your custom logic after the parent call. Link to comment Share on other sites More sharing options...
gostbuster Posted October 13, 2014 Share Posted October 13, 2014 (edited) The best way is definetelly to use the override. There is by the way a tip : If you use parent::postProcess you may execute the parent method, But what you would do instead is to use FrontController::method() to avoid passing by parent class while overriding Edited October 13, 2014 by gostbuster (see edit history) Link to comment Share on other sites More sharing options...
bellini13 Posted October 13, 2014 Share Posted October 13, 2014 The best way is definetelly to use the override. You don't even know what they want to do, how can you jump to the conclusion that an override is the best way Link to comment Share on other sites More sharing options...
abdullacm Posted October 14, 2014 Author Share Posted October 14, 2014 i could accomplish this, placed cartController in my module's override folder and written a condition postProcess(){ if(Module::isEnabled('my-module-name') { //my logic goes here } else { //non modified code here } } so the modified code is executed only if the module is enabled thanks for the replies. Link to comment Share on other sites More sharing options...
Rolige Posted October 14, 2014 Share Posted October 14, 2014 The easy way is by overriding the controller as bellini13 has mentioned, and the other way is using one hook of the shopping cart. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now