1

We have a website with 2 store views.

One is the frontend that the public sees the other is an 'offline' store that runs a POS system for our staff. I want the offline store to be a completely standard version of magento i.e. run none of the many theme and extra modules we have running on our live store.

I have set the theme to default but now I need to disable the modules. Is there a way to edit the module.xml files so that for the particular store view <active>false</active> or something that achieves that?

2 Answers 2

2

First Move app/code/core/Mage/Core/Model/Config.php to app/code/local/Mage/Core/Model/Config.php

Now open app/code/local/Mage/Core/Model/Config.php and find method called loadModulesConfiguration and add the following code to make the method look like this.

public function loadModulesConfiguration($fileName, $mergeToObject = null, $mergeModel=null)
{
    $disableLocalModules = !$this->_canUseLocalModules();

    if ($mergeToObject === null) {
        $mergeToObject = clone $this->_prototype;
        $mergeToObject->loadString('<config/>');
    }
    if ($mergeModel === null) {
        $mergeModel = clone $this->_prototype;
    }
    $modules = $this->getNode('modules')->children();
    foreach ($modules as $modName=>$module) {
        if ($module->is('active')) {
            // Begin additional code
            if((bool)$module->restricted) {
                $restricted = explode(',', (string)$module->restricted);
                $runCode = (isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : 'default');
                if(in_array($runCode, $restricted)) {
                    continue;
                }
            }
            // End additional code
            if ($disableLocalModules && ('local' === (string)$module->codePool)) {
                continue;
            }
            if (!is_array($fileName)) {
                $fileName = array($fileName);
            }

            foreach ($fileName as $configFile) {
                $configFile = $this->getModuleDir('etc', $modName).DS.$configFile;
                if ($mergeModel->loadFile($configFile)) {
                    $mergeToObject->extend($mergeModel, true);
                }
            }
        }
    }
    return $mergeToObject;
}

Now Edit your module.xml file

<?xml version="1.0"?>
<config>
    <modules>
        <MyPackage_MyModule>
            <active>false</active>
            <restricted>mystore1,mystore4,mystore5</restricted>
            <codePool>local</codePool>
        </MyPackage_MyModule>
    </modules>
</config>
6
  • This is a nice approach (+1), but what if you didn't set up the store views using the $_SERVER['MAGE_RUN_CODE'] var? What if I have a subfolder with a cloned index.php?
    – Marius
    Commented Jan 17, 2017 at 7:30
  • Do I add the store I want to enable the module on in the restricted tag?
    – Pragman
    Commented Jan 17, 2017 at 7:34
  • With this, the module will not even load while on the stores with a store code of mystore1, mystore4, or mystore5. The <restricted> tag is entirely optional, if you omit it the module will load as it normally would. Commented Jan 17, 2017 at 7:41
  • But you have <active>false</active> which disables the module for all store views correct? Regardless of the restricted tag. There fore should i set <active>true</active> and the store views that i want the module disabled for in the restricted tag?
    – Pragman
    Commented Jan 17, 2017 at 7:47
  • ok lets you check both option <active>false</active> and <active>true</active> and keep the which one is work for you. Commented Jan 17, 2017 at 7:54
0

Modules cannot be disabled at store view level.

You can disable the output of the non-core modules for that specific store view by going to System->configuration->Advanced->Advanced and selecting the store view you need from the top left selector.
But this won't completely disable the modules. For example, if you have custom observer, they will still fire.

If you want to completely disable the functionality of a module at store view level, you need to add for each module a yes/no config setting.
Let's say the path is [module]/settings/enabled.
Then, in each method that directly affects the website (usually public methods) you need to add this at the top of it:

If the method overrides a code method :

if (Mage::getStoreConfigFlag(`[module]/settings/enabled`)) {
    return parent::[methodNameHere](parameters here);
}

if it's not an override you can do this:

if (Mage::getStoreConfigFlag(`[module]/settings/enabled`)) {
    return 'check what type the method needs to return'; //you can return false or $this or whatever.
}

I know this requires a lot of code but it's the cleanest way to do it.
Then, in order to disable a module for a store view you can simply go to the backend and set that flag mentioned above to no for the desired store view.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.