【问题标题】:Magento load modules by website/storeMagento 通过网站/商店加载模块
【发布时间】:2015-12-01 17:25:55
【问题描述】:

我正在开发一个已经有一个商店的网站,并且我正在尝试让第二个商店/网站正常运行。

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

在线搜索并没有找到完整的解决方案。在this other post 上,用户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';
}

这将完成这项工作,但存在一些问题:

  • 清除缓存可能不起作用
  • 更新不会自动应用,因为我们从核心复制了这些文件

还有其他方法吗?

此帖continues here

【问题讨论】:

  • 这还有另一个问题,如果您的默认商店(访问管理区域的那个)禁用了模块,它们将不会显示在管理区域中进行配置。使它成为一个不太好的解决方案

标签: php magento caching


【解决方案1】:

在高级下禁用后端每个商店的模块输出。然后编辑您的模块观察器函数并检查该配置以禁用完整的模块功能:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-05
    相关资源
    最近更新 更多