Jump to content

Overriding module PHP file


Recommended Posts

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.

  • Like 1
Link to comment
Share on other sites

  • 1 year later...
  • 4 months later...

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 by Visiedo (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 1 year later...

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

  • 3 weeks later...

 

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

  • 1 month later...

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...