Magento – Disable module output using XML for web site

UnnamedIt can happen every now and again, that there are problems with extensions, e.g. the. are only licensed for one domain. About the backend the extension then only in respect of this website is a / to a shop with the domain enabled and disabled for all other but the extension affects the other stores and hinders or prevents the display in the front end.

Different extensions which are also activated and deactivated from home and there is no configuration option, to define in which shop or. which site the extension should not be activated, and where.

I thought, but that there must be a way directly into the module Some incorporate XML in the folder etc / modules in the respective extension.xml, that it is “if site X, be active; if Y then inactive site”.

After some Search and thought I found the solution:

1. If the config.php copied from the folder app / code / core / Mage / Core / Model in the folder app / code / local / Mage / Core / Model there and then about. from line 850 after

        $modules = $this->getNode('Modules')->children();
        foreach ($modules as $modName=>$module) {
            if ($module->is('Active')) {

search.

Dort wird dann

            // Website Restriction Start
            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;
                }
            }
            // Website Restriktion Ende

inserted, so dass der gesamte Code dann so aussieht:

    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')) {
            // Website Restriction Start
            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;
                }
            }
            // Website Restriction End
                if ($disableLocalModules && ('Local' === (string)$module->codePool)) {
                    continue;
                }
                $configFile = $this->getModuleDir('Etc', $modName).DS.$fileName;
                if ($mergeModel->loadFile($configFile)) {
                    $mergeToObject->extend($mergeModel, true);
                }
            }
        }
        return $mergeToObject;
    }

Mit diesen Zeilen wird Magento angewiesen darauf zu achten, ob in der Modul XML eine Restriktion definiert wird oder nicht.

Um nun eine solche zu setzen, öffnet man die entsprechende [Module].xml und fügt vor den <codePool> the line

<restricted>[der code des auszuschließenden Shops, can be separated by comma if more stores]</restricted>

Since it can be at the whole issue of, that it is a multi-store, So multiple websites from a Magento backend, it is still important, that the distribution of stores by the $ _SERVER variable “MAGE_RUN_CODE” defined. This takes you e.g.. in the index.php in the root directory.

switch($_SERVER['HTTP_HOST']) {

// Shop 1

case 'shop1.de';
case 'www.shop1.de';

$_SERVER["MAGE_RUN_CODE"] = "shop1";

$_SERVER["MAGE_RUN_TYPE"] = "website";

break; 

// Shop2 (default store)

default:

$_SERVER["MAGE_RUN_CODE"] = "shop2";

$_SERVER["MAGE_RUN_TYPE"] = "website";

break;

So you would e.g. here. “shop1” use as restricted, if the module is not active here.

Important: Clear cache. Most secure method and the cache folder in the var rename and / or delete. Magento automatically creates a new one.

Used in Magento Version 1.4.1.1 Comments? Additions? Notes? Gladly!

Published by Covos

Since 2009 I have been working intensively with Magento. I started with the creation and operation of B2C stores. This was extended through my work in the logistics sector. This resulted first specialized B2E systems. Today I work day-a day with exciting B2C, B2B- and B2E projects and reports in this blog about challenges and give insider tips.

Leave a Reply

Your email address will not be published. Required fields are marked *