在magento中编辑配置值(magento扩展)

时间:2012-12-17 23:15:26

标签: magento

我创建了一个Magento扩展,它使用/ etc / dir(对于我的模块)中的system.xml文件向我的配置添加字段。 Magento 1.5目前是我的目标系统,但我也打算将兼容性扩展到1.4和.16

<merchantid translate="label">
      <label>Merchant ID</label>
      <frontend_type>text</frontend_type>
      <sort_order>20</sort_order>
      <show_in_default>1</show_in_default>
      <show_in_website>1</show_in_website>
      <show_in_store>0</show_in_store>
</merchantid>

我正在尝试在运行时填充此字段的值。目前,我在我的插件中运行它:Mage::getStoreConfig('payment/mymerchant/merchantid');,它返回字段中填充的值。

我需要能够以编程方式更新此字段,我尝试了这个:

 $installer = new Mage_Core_Model_Resource_Setup();
                $installer->startSetup();
                $installer->setConfigData("payment/mymerchant/merchantid", "TEST");
                $installer->endSetup();

但没有成功。我在搜索问题时遇到了麻烦,因为大多数结果似乎都不相关。

有没有人知道如何设置这些值?

1 个答案:

答案 0 :(得分:5)

如果您正在寻找默认值,您可以这样做:

<config>
...
    <default>
        <payment>
            <ezimerchant>
                <merchantid>TEST</merchantid>
            </ezimerchant>
        </payment>
    </default>
</config>

如果您真的在寻找程序化解决方案,可以执行以下操作:

$configModel = Mage::getModel('core/config');
$configModel->saveConfig('payment/ezimerchant/merchantid','TEST');

第三个参数是应对保存它,'默认','网站','商店'。第四个参数定义要将其保存的网站ID或商店ID。

编辑:您必须在执行此操作时禁用缓存,或者之后刷新/刷新缓存以使更改生效。