覆盖Magento配置 [英] Override Magento Config

查看:72
本文介绍了覆盖Magento配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种无需更改默认值即可覆盖Magento配置的好的解决方案.

I am looking for a good solution to override the Magento config without changing the default values.

例如,我要覆盖core_config_data表中的"web/unsecure/base_skin_url"项,而不删除现有值.因此,如果在代码中的任何位置都可以调用此确切的代码:

For example, I want to override the "web/unsecure/base_skin_url" item in the core_config_data table without deleting the existing value. So if anywhere in the code this exact code is called:

Mage::getStoreConfig('web/unsecure/base_skin_url');

它将找到我设置的配置选项,而不是默认选项...

It will find the config option I set and not the default one...

提前谢谢!

查克

推荐答案

Magento在运行时直接从配置对象的树结构中读取其配置值,因此您需要使用配置对象的本机setNode方法来更改值.但是,由于Magento 加载作用域配置(自我链接)的方式,它并不那么直接看起来向前.

Magento reads its configuration values at runtime directly from the configuration object's tree structure, so you need to use the configuration object's native setNode method to change the values. However, because of the way Magento loads in scoped configuration (self link), it's not as straight forward as it seems.

对于当前版本的Magento(我相信,但尚未测试,对于较旧的版本),您需要在节点集中为当前store设置配置值.

With current versions of Magento (and I believe, but have not tested, with older versions), you'll need to set the configuration value in the set of nodes for the current store.

第一步是获取当前设置商店的代码.您可以通过以下方式以编程方式完成此操作

Step one is getting the code for the currently set store. You can do this programmatically with the following

$store = Mage::app()->getStore();
$code  = $store->getCode();

然后,您可以通过以下调用设置配置值

then, you can set a configuration value with the following call

$config = Mage::getConfig();
$config->setNode("stores/$code/web/unsecure/base_skin_url", 'value_to_set');

请记住,这一切都需要在Magento自举配置对象之后发生.另外请记住,在一段时间内Magento将具有已加载的配置,但不会加载store对象.如果是这种情况,您将无法从商店对象加载商店代码.

Keep in mind this all needs to happen after Magento has bootstrapped the configuration object. Also keep in mind there's a period of time where Magento will have a loaded configuration, but the store object will not be loaded. If this is the case you will not be able to load the store code from the store object.

我在脉冲风暴混沌模块中做了类似的事情.如果您对工作代码感兴趣,请访问

I did something similar in my Pulse Storm Chaos module. If you're interested in working code it's on Github.

这篇关于覆盖Magento配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆