Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Suppose, I have 3 stores.

I want to disable a module in Store 2. I only want it to be enabled in Store 1 and Store 3.

I see that I can do it by:-

  • Going to System -> Configuration -> Advanced

  • Selecting desired store from Current Configuration Scope dropdown list.

But this does not work fully.

And, I also don't want to check store in the module code itself or create system configuration field for the module to check/uncheck store to enable/disable.

What I am expecting is by adding some code in app/etc/modules/MyNamespace_MyModule.xml. Can we do it this way?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
476 views
Welcome To Ask or Share your Answers For Others

1 Answer

To disable a module on the store scope, I've found it's possible to do it like this:

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

Inside Config.php find the method "loadModulesConfiguration" Don't change anything, but 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;
}

The new code will cause the method to also check for a new node in the module xml file, <restricted>. If the node exists, the value would be a comma separated list of store codes that you do NOT want the module to load on. If you have multiple stores, the $_SERVER variable "MAGE_RUN_CODE" should be set with the current store code. If it's not set, the script will fallback to assuming the store code is "default" which is what it is by default unless for some bizarre reason you decide to change that in the backend.

A modules xml file could then look like this:

<?xml version="1.0"?>
<config>
    <modules>
        <MyPackage_MyModule>
            <active>false</active>
            <restricted>mystore1,mystore4,mystore5</restricted>
            <codePool>local</codePool>
        </MyPackage_MyModule>
    </modules>
</config>

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...