Jump to content

Shouldn't overrides be disabled when a module is disabled?


marcis

Recommended Posts

Edit classes/module/Module.php. Find "public function disable($forceAll = false)", add the following to the end of the function:

$this->uninstallOverrides();

 

Find "public function enable($forceAll = false)", add the following before the "return true":

 

$this->installOverrides();

 

Now the overrides are disabled when the module is disabled.

  • Like 1
Link to comment
Share on other sites

You may not want to remove your class overried on a disable. This is because of MultiShop, if the module is disabled on one shop but enabled on other shops then you don't want to remove the override.

 

enable/disable in my module with parms

public function enable/disable ($forceAll = false)

 

then in my class override I check the module is enabled

 

if (Module::isEnabled('my_module_name')

 

you may consider developing with error E_ALL or at least E_STIRCT, this would tell you that you are missing $forceAll = false

Note: the above code runs in 1.4 and 1.5

Edited by elpatron (see edit history)
  • Like 1
Link to comment
Share on other sites

another piece of advice...avoid overrides at all costs...if you can use a hook, then all is taken care of for you by ps. I used to be a big override fan until I found out how complicated it is to manage them...i.e. if override exists etc....

 

and if you run with E_STIRCT you would have found out about he enable/disable parms

 

suerte

Edited by elpatron (see edit history)
  • Like 1
Link to comment
Share on other sites

Instead of overriding the controller itself you are suggesting me to use a hook?

 

So... if I want to modify the contact form, I guess I can use the displayHome hook and then... checking the name of the page? What else will I need? A new customized controller? How can I prevent the default contact form from showing?

 

Thank you!

Link to comment
Share on other sites

  • 7 months later...

You may not want to remove your class overried on a disable. This is because of MultiShop, if the module is disabled on one shop but enabled on other shops then you don't want to remove the override.

 

enable/disable in my module with parms

public function enable/disable ($forceAll = false)
then in my class override I check the module is enabled

 

if (Module::isEnabled('my_module_name')
you may consider developing with error E_ALL or at least E_STIRCT, this would tell you that you are missing $forceAll = false

Note: the above code runs in 1.4 and 1.5

 

i got some modules that over rides the other. since these modules belong to different themes and all themes are used by different shop. hence i don't want to disable any of the modules. Can i have a suggestion so that the modules doesn't override. 

Link to comment
Share on other sites

  • 4 weeks later...

Hello,

I'd prefer to disable the module for one shop (undoing the override) and not for the others.have you a solution please?

 

the way I handle this, for multistore and also in 1.4, is check in the override if the module is enabled. 

 

This would seem a sensible approach. 

 

in class override

if (Module::isEnabled('your_module_name')

Link to comment
Share on other sites

 thank you Sir but where i can find the file.php responsible for the execution of all override in prestashop?

In my module in put this change:


public function install()

{......


// Install overrides

    try {

if (Module::isEnabled('mymodule'){

        $this->installOverrides();}

    } catch (Exception $e) {

        $this->_errors[] = sprintf(Tools::displayError('Unable to install override: %s'), $e->getMessage());

        $this->uninstallOverrides();

        return false;

    }

.........}

it's this that you mean ?

Link to comment
Share on other sites

 

 thank you Sir but where i can find the file.php responsible for the execution of all override in prestashop?
In my module in put this change:
public function install()
{......
// Install overrides
    try {
if (Module::isEnabled('mymodule'){
        $this->installOverrides();}
    } catch (Exception $e) {
        $this->_errors[] = sprintf(Tools::displayError('Unable to install override: %s'), $e->getMessage());
        $this->uninstallOverrides();
        return false;
    }
.........}
it's this that you mean ?

 

 

this is coding for 1.4 yes?

 

for 1.5 you overrides when placed in proper module folder will be 'automatically' installed in the override directory.  So you only need to install them programatically in 1.4

 

this might help

http://doc.prestashop.com/display/PS15/Creating+a+PrestaShop+module

 

note you should use hooks whenever possible (PrestaShop has just started rejecting modules for offical addon's that use overrides).

Link to comment
Share on other sites

No , it's coding for 1.5 ,

In my module i created a folder "override" when i installed my module the override exucting automatically ,here is the code responsible in the function install() of module

  // Install overrides
    try {
 
        $this->installOverrides();
    } catch (Exception $e) {
        $this->_errors[] = sprintf(Tools::displayError('Unable to install override: %s'), $e->getMessage());
        $this->uninstallOverrides();
        return false;
    }
Now i made this change 
public function install()
{......
// Install overrides
    try {
if (Module::isEnabled('mymodule'){
        $this->installOverrides();}
    } catch (Exception $e) {
        $this->_errors[] = sprintf(Tools::displayError('Unable to install override: %s'), $e->getMessage());
        $this->uninstallOverrides();
        return false;
    }
.........}
it's Ok Sir? ... :)
Link to comment
Share on other sites

in 1.5...the ovrerride will exist in the override folder...until  the module is uninstalled.  It is then remove by PrestaShop

 

if you want a module, after installation to work in multistore...i.e. enabled in some shop(s), and disabled in other shop(s).

 

then simply add the this code at INTO your class override.

if (Module::isEnabled('your_module_name')

 

this way if the override is called but the module is not enabled  'for this shop context', you can take appropriate action. 

 

Note: a module when is disabled for that current shop, will never get control.

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...