sttaq Posted May 10, 2014 Share Posted May 10, 2014 (edited) Hi I want to find out if I can override an existing Admin controller from a module. I have tried to put my override in following location: modules/mymodule/override/controllers/admin and a class in modules/mymodule/classes folder. Once these are in place I cleared the cache from back office and also removed the file class_index.php file. So far I have failed to see that if my override is being loaded and I am only getting the default behavior. I have also removed all the calls to parent with AdminController in my override. After failing this I tried placing same files in following locations: mywebsiteroot/override/controllers/admin and mywebsiteroot/override/classes and after clearing cache PrestaShop loads my override and shows the expected behavior. My question: Why can't I override from inside a module? I have noticed that I do not have an index.php file in my override folders. Do I need an index.php file and if yes then what should I put in it? or am I missing something else? Another thing to add: Because I am currently developing the module, I have placed these new classes after I have installed the module from back office. Does it make any difference? Thanks Edited May 10, 2014 by sttaq (see edit history) Link to comment Share on other sites More sharing options...
sttaq Posted May 10, 2014 Author Share Posted May 10, 2014 (edited) I think I am getting close to my objective. Installing a module does in fact trigger PrestaShop to scan any overrides in my modules folder. So now I have got my override properly loaded. The only problem now is that I want to use a custom class inside my override and installing my module does not load this class. I have tried placing this class under modules/mymodule/override/classes folder and also modules/mymodule/classes folder but it does not load and when my admin controller is called an exception is thrown saying that my class cannot be found. Can you please help me in getting this class properly loaded? Thanks EDIT: My guess is that I need to have require_once either in the overriden controller or in the module class file. I have attempted to put it at both place but have failed and not sure if I am setting the correct paths. Edited May 10, 2014 by sttaq (see edit history) Link to comment Share on other sites More sharing options...
gonebdg - webindoshop.com Posted May 12, 2014 Share Posted May 12, 2014 Your custom class can be placed anywhere, but you should load the clasess file correctlyUse require_once or inlcude_once, it depend to your need. Check that the class exists before trying to use it require_once('PATH_TO_YOUR_CLASSES_FILE'); if (class_exists('MyClass')) { $myclass = new MyClass(); } OR debugging to make sure your require_once or include_once function was referred to the classes file correctly // die if(file_exists('PATH_TO_YOUR_CLASSES_FILE')) d('Path to classes file is correct'); else d('Incorrect path to classes file'); What is your prestashop version ? 1 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