Magento: Disable module for any particular store

前端 未结 5 974
耶瑟儿~
耶瑟儿~ 2020-12-15 09:28

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

5条回答
  •  别那么骄傲
    2020-12-15 09:55

    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('');
        }
        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, . 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:

    
    
        
            
                false
                mystore1,mystore4,mystore5
                local
            
        
    
    

    With this, the module will not even load while on the stores with a store code of mystore1, mystore4, or mystore5. The tag is entirely optional, if you omit it the module will load as it normally would.

提交回复
热议问题