Magento 版本兼容
Magento version compatible with
我需要能够在模块的 config.xml:
中指定 Magento 版本兼容性
<config>
<modules>
<MyCompany_MyModule>
<version>0.9.0</version>
<minimum_version>1.7</minimum_version>
</MyCompany_MyModule>
</modules>
...
这样看起来对吗?
所以在普通的 Magento 中 config.xml 中没有 minimum_version
标签,有一些方法可以实现这种功能。
- 如果您在 Magento Connect 上制作扩展 public,您可以指定扩展兼容的版本,
- 您可以使用某种事件来检查您使用的是哪个版本的 Magento,然后根据该版本激活您的扩展程序,
- 通过检查 Magento 版本简单包装您的扩展函数调用,
我自己使用了最后一步,不是在检查版本时,而是在 Magento 管理系统配置中为扩展添加活动标志时。
在一天结束的时候,我意识到我可以把我需要的东西放在我喜欢的地方。据我所知,没有 Magento 最佳实践。我的问题是需要使用 modman 从 Github 部署模块列表。这是一些骇人听闻的代码,其中 xml 最终被使用:
... //after cloning the repositories, for each module:
$modules = glob('.modman/$moduleName/app/etc/modules/*.xml');
$filename = $modules[0];
$xmlString = file_get_contents($filename, FILE_TEXT);
$xml = simplexml_load_string($xmlString);
$jsonStr = json_encode($xml);
$obj = json_decode($jsonStr);
$modules = $obj->modules;
foreach ($modules as $key=>$module){}
$fullName = explode('_', $key);
$namespace = $fullName[0];
$codePool = $module->codePool;
$channel = $codePool;
$configFile = ".modman/$moduleName/app/code/$channel/$namespace/$moduleName/etc/config.xml";
$configXml = file_get_contents($configFile, FILE_TEXT);
$xml = simplexml_load_string($configXml);
$jsonStr = json_encode($xml);
$obj = json_decode($jsonStr);
$modules = $obj->modules;
$module = reset($modules);
if (isset($module->minimum_version)) {
$minimumVersion = $module->minimum_version;
$magentoVersion = Mage::getVersion();
$tooOld = version_compare($magentoVersion, $minimumVersion, '<');
if ($tooOld < 0) {
$exec = "modman remove $name";
exec($exec, $output);
}
}
完成。
我需要能够在模块的 config.xml:
中指定 Magento 版本兼容性<config>
<modules>
<MyCompany_MyModule>
<version>0.9.0</version>
<minimum_version>1.7</minimum_version>
</MyCompany_MyModule>
</modules>
...
这样看起来对吗?
所以在普通的 Magento 中 config.xml 中没有 minimum_version
标签,有一些方法可以实现这种功能。
- 如果您在 Magento Connect 上制作扩展 public,您可以指定扩展兼容的版本,
- 您可以使用某种事件来检查您使用的是哪个版本的 Magento,然后根据该版本激活您的扩展程序,
- 通过检查 Magento 版本简单包装您的扩展函数调用,
我自己使用了最后一步,不是在检查版本时,而是在 Magento 管理系统配置中为扩展添加活动标志时。
在一天结束的时候,我意识到我可以把我需要的东西放在我喜欢的地方。据我所知,没有 Magento 最佳实践。我的问题是需要使用 modman 从 Github 部署模块列表。这是一些骇人听闻的代码,其中 xml 最终被使用:
... //after cloning the repositories, for each module:
$modules = glob('.modman/$moduleName/app/etc/modules/*.xml');
$filename = $modules[0];
$xmlString = file_get_contents($filename, FILE_TEXT);
$xml = simplexml_load_string($xmlString);
$jsonStr = json_encode($xml);
$obj = json_decode($jsonStr);
$modules = $obj->modules;
foreach ($modules as $key=>$module){}
$fullName = explode('_', $key);
$namespace = $fullName[0];
$codePool = $module->codePool;
$channel = $codePool;
$configFile = ".modman/$moduleName/app/code/$channel/$namespace/$moduleName/etc/config.xml";
$configXml = file_get_contents($configFile, FILE_TEXT);
$xml = simplexml_load_string($configXml);
$jsonStr = json_encode($xml);
$obj = json_decode($jsonStr);
$modules = $obj->modules;
$module = reset($modules);
if (isset($module->minimum_version)) {
$minimumVersion = $module->minimum_version;
$magentoVersion = Mage::getVersion();
$tooOld = version_compare($magentoVersion, $minimumVersion, '<');
if ($tooOld < 0) {
$exec = "modman remove $name";
exec($exec, $output);
}
}
完成。