jumbo Posted November 7, 2011 Share Posted November 7, 2011 Hi I searched for an answer to this, but couldn't find a clear answer Please I need a clear answer to this for once! I want to know if it's possible to override a module's PHP file. I know it is possible for tpl and I know how to do it. But I need to modify a function in a module's PHP file. Thank you. 1 Link to comment Share on other sites More sharing options...
tomerg3 Posted November 7, 2011 Share Posted November 7, 2011 no, it's not, you have to actually replace the file. Link to comment Share on other sites More sharing options...
jumbo Posted November 8, 2011 Author Share Posted November 8, 2011 no, it's not, you have to actually replace the file. This means that, when I update the module, my changes will be discarded... Link to comment Share on other sites More sharing options...
tomerg3 Posted November 8, 2011 Share Posted November 8, 2011 Yes, but as modules often change, it's not very likely that an override would work anyway, especially if the module code is not well organized and structured.. Link to comment Share on other sites More sharing options...
WIZZAH Posted January 9, 2013 Share Posted January 9, 2013 Is this stilll true in the 1.5x version? No way to change module behavior other then through the template files? Link to comment Share on other sites More sharing options...
Visiedo Posted May 26, 2013 Share Posted May 26, 2013 (edited) I think the easiest and safest way to do it is just to rename the module. Let's say you would like to override the module "blockcategories": Copy the module to a new folder, e.g. myblockcategories, with all the files, and preserving the directory structure In the new folder, rename blockcategories.php, .tpl, .css by "myblockcategories". Rename the name of the class and information in the construct method: class MyBlockCategories extends Module { public function __construct() { $this->name = 'myblockcategories'; $this->tab = 'front_office_features'; $this->version = '2.0'; $this->author = 'PrestaShop' parent::__construct(); $this->displayName = $this->l('My custom Categories block'); $this->description = $this->l('Adds a block featuring product categories. Custom version'); } Now modify the. Php as desired. Once you are done you should install the newly created module. Start by disabling / uninstall the original module in the back office. Then search for your module and install it. Please let me know if you need more details Edited May 27, 2013 by Visiedo (see edit history) 1 Link to comment Share on other sites More sharing options...
bibisha Posted February 18, 2015 Share Posted February 18, 2015 Go to : override/modules/ {module folder} here 'MyModule' is the module name And follow this code pattern in mymodule.php <?php if (!defined('_CAN_LOAD_FILES_')) exit; class MyModuleOverride extends MyModule { } Link to comment Share on other sites More sharing options...
Daniel - PrestaBR Posted March 7, 2015 Share Posted March 7, 2015 Go to : override/modules/ {module folder} here 'MyModule' is the module name And follow this code pattern in mymodule.php <?php if (!defined('_CAN_LOAD_FILES_')) exit; class MyModuleOverride extends MyModule { } That is good news! I wonder why they didn't update the docs. Link to comment Share on other sites More sharing options...
jgamio Posted March 8, 2015 Share Posted March 8, 2015 These work on all version ? Link to comment Share on other sites More sharing options...
bellini13 Posted March 8, 2015 Share Posted March 8, 2015 only since PS v1.6.0.11 Link to comment Share on other sites More sharing options...
Dev Franco Posted April 9, 2015 Share Posted April 9, 2015 Hi, If I use override folder, need to move all the module files into it?? or only the files to be changed? Link to comment Share on other sites More sharing options...
bellini13 Posted April 9, 2015 Share Posted April 9, 2015 i believe it is just the main module file that can be overriden, you would only move that one file Link to comment Share on other sites More sharing options...
PascalVG Posted April 9, 2015 Share Posted April 9, 2015 Nemo1 wrote some article about it here Link to comment Share on other sites More sharing options...
Dev Franco Posted April 10, 2015 Share Posted April 10, 2015 Hi, As in the topic, I have added the blocktopmenu module to override folder and done the changes. Now I updated blocktopmenu module through admin to know what will happen after update and it produced an error. Fatal error: Access level to BlocktopmenuOverride::makeMenuOption() must be protected (as in class Blocktopmenu) or weaker in D:\projects\beverenps\override\modules\blocktopmenu\blocktopmenu.php on line 1372 What does it mean?? Please help. Link to comment Share on other sites More sharing options...
jgamio Posted April 10, 2015 Share Posted April 10, 2015 Did you make a public function on the override ? Link to comment Share on other sites More sharing options...
Dev Franco Posted April 10, 2015 Share Posted April 10, 2015 No. Please make it more clear. Link to comment Share on other sites More sharing options...
jgamio Posted April 10, 2015 Share Posted April 10, 2015 How do you declare the function must be protected sound like the function is private or proteted and you are declaring public Link to comment Share on other sites More sharing options...
Dev Franco Posted April 10, 2015 Share Posted April 10, 2015 No, the function is private. I didn't change the function scope. Link to comment Share on other sites More sharing options...
tuk66 Posted April 10, 2015 Share Posted April 10, 2015 You cannot override private method (makeMenuOption). Only public and protected ones. Link to comment Share on other sites More sharing options...
Dev Franco Posted April 10, 2015 Share Posted April 10, 2015 But the override worked . The problem occured only when updating the module. Link to comment Share on other sites More sharing options...
bellini13 Posted April 10, 2015 Share Posted April 10, 2015 most likely the function was not private in the previous version... 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