Muk*_*ain 12 configuration module magento
假设,我有3家商店.
我想禁用商店2中的模块.我只想在商店1和商店3中启用它.
我看到我能做到: -
转到系统 - >配置 - >高级
从Current Configuration Scope下拉列表中选择所需的商店.
但这并不完全有效.
并且,我也不想在模块代码本身中检查存储,或者为模块创建系统配置字段以检查/取消选中存储以启用/禁用.
我期待的是在app/etc/modules/MyNamespace_MyModule.xml中添加一些代码.我们可以这样做吗?
小智 16
要禁用商店范围上的模块,我发现可以这样做:
将app/code/core/Mage/Core/Model/Config.php移动到app/code/local/Mage/Core/Model/Config.php
在Config.php中找到方法"loadModulesConfiguration"不要改变任何东西,但添加以下代码使方法看起来像这样.
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;
}
Run Code Online (Sandbox Code Playgroud)
新代码将导致该方法还检查模块xml文件中的新节点<restricted>.如果节点存在,则该值将是您不希望模块加载的以逗号分隔的商店代码列表.如果您有多个商店,则应使用当前商店代码设置$ _SERVER变量"MAGE_RUN_CODE".如果没有设置,脚本将回退到假定商店代码是"默认",这是默认情况下的,除非出于某些奇怪的原因你决定在后端更改它.
模块xml文件可能如下所示:
<?xml version="1.0"?>
<config>
<modules>
<MyPackage_MyModule>
<active>false</active>
<restricted>mystore1,mystore4,mystore5</restricted>
<codePool>local</codePool>
</MyPackage_MyModule>
</modules>
</config>
Run Code Online (Sandbox Code Playgroud)
有了这个,模块甚至不会在商店代码为mystore1,mystore4或mystore5的商店上加载.<restricted>标签完全是可选的,如果省略它,模块将按正常方式加载.
此配置只是禁用了前端布局中的模块输出,但是模块控制器,事件观察器,管理页面等仍在工作。
另外,不要忘记在布局文件定义中指定模块名称,否则将为特定商店加载所有布局文件内容:
<config>
<layout>
<module_alias module="Module_Name">
<file>yourlayoutfile.xml</file>
</module_alias>
</layout>
</config>
Run Code Online (Sandbox Code Playgroud)
如果要开发模块,并且想在特定商店的前端禁用全部功能,则应创建“是/否”类型的配置字段,并通过Mage :: getStoreConfigFlag('config / field /路径”)。
| 归档时间: |
|
| 查看次数: |
9269 次 |
| 最近记录: |