Magento通过网站/商店加载模块


Magento load modules by website/store

我正在开发一个已经有一个商店的webiste,我正在努力让第二个商店/网站正常工作。

新网站有一个模板,其中包括一些观测器,即使我通过系统->配置->高级禁用模块,因为这只是禁用模块输出,而不是实际的模块,因此,如果有任何观测器,它们仍将被加载并运行。

已在线搜索,但未找到完整的解决方案。在另一篇文章中,用户Eric Hainer提出了一个解决方案,允许根据检查$_SERVER['MAGE_RUN_CODE']变量加载模块,但如果缓存处于活动状态,则此解决方案不起作用,因为当加载包含模块的存储时,会将模块放入缓存。

所以我的解决方案是修改文件app/code/core/Mage/core/Model/Config/Options.php,根据存储将缓存保存在不同的文件夹中

首先,我将文件复制到app/code/local/Mage/Core/Model/Config/Options.php,以避免更改核心文件

在构造函数上添加了以下行

//custom code to save cache on different folders per website
$runCode = (isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : 'default');
$this->_data['cache_dir']   = $this->_data['var_dir'].DS.'cache'.$runCode;

以下是构造函数看起来像的样子

protected function _construct()
{
    $appRoot= Mage::getRoot();
    $root   = dirname($appRoot);
    $this->_data['app_dir']     = $appRoot;
    $this->_data['base_dir']    = $root;
    $this->_data['code_dir']    = $appRoot.DS.'code';
    $this->_data['design_dir']  = $appRoot.DS.'design';
    $this->_data['etc_dir']     = $appRoot.DS.'etc';
    $this->_data['lib_dir']     = $root.DS.'lib';
    $this->_data['locale_dir']  = $appRoot.DS.'locale';
    $this->_data['media_dir']   = $root.DS.'media';
    $this->_data['skin_dir']    = $root.DS.'skin';
    $this->_data['var_dir']     = $this->getVarDir();
    $this->_data['tmp_dir']     = $this->_data['var_dir'].DS.'tmp';
    //custom code to save cache on different folders per website
    $runCode = (isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : 'default');
    $this->_data['cache_dir']   = $this->_data['var_dir'].DS.'cache'.$runCode;
    $this->_data['log_dir']     = $this->_data['var_dir'].DS.'log';
    $this->_data['session_dir'] = $this->_data['var_dir'].DS.'session';
    $this->_data['upload_dir']  = $this->_data['media_dir'].DS.'upload';
    $this->_data['export_dir']  = $this->_data['var_dir'].DS.'export';
}

这将完成工作,但有一些问题:

  • 清除缓存可能不起作用
  • 当我们从核心复制此文件时,更新将不会自动应用

还有别的办法吗?

这篇文章在这里继续

在高级下禁用后端中每个存储的模块输出。然后编辑您的模块观察员功能并检查该配置以禁用完整的模块功能:

if(Mage::getStoreConfigFlag('advanced/modules_disable_output/YOUR_MODULE'))
    return false;

大多数社区模块已经有了自己的配置来启用/禁用每个商店的功能。