1

I've created a Magento extension which uses the system.xml file in my /etc/ dir (for my module) to add fields to my configuration. Magento 1.5 is my target system at the moment, but I also intend to extend compatibility to 1.4 and .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>

I'm trying to populate the value of this field during runtime. Currently, I am running this inside my plugin: Mage::getStoreConfig('payment/mymerchant/merchantid'); which returns the value populated in the field.

I need to be able to update this field programatically, I tried this:

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

But had no success. I am having trouble googling the problem too because most results don't appear relevant.

Does anyone have anyidea how I can set these values?

2
  • Are you looking for default values for these configurations? Or does the value need to be different depending on other factors? Commented Dec 17, 2012 at 23:17
  • it needs to be different depending on the situation. How does one set the default value anyway? Commented Dec 17, 2012 at 23:20

1 Answer 1

5

If you're looking for default values you can do:

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

If you are really looking for a programmatic solution you can do the following:

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

The third parameter is what cope to save it, 'default', 'website', 'store'. The fourth parameter defines which Website ID or Store ID you want to save it with.

Edit: You must either disable cache when doing this or refresh/flush cache afterwards for the change to take effect.

Sign up to request clarification or add additional context in comments.

2 Comments

Great. You know what? the $installer code I used actually does work, you just have to refresh twice because if you do a set and then a get in magento it will ignore the DB and read from memory. +1 anyway as this looks good. will use in the future. Thanks
It's not that the DB settings are ignored, it's just that the configuration is already parsed into memory for the current execution scope. This can be overcome by setting both config XML and the install script data, or by explicitly calling loadDb() on the config object at the end of the setup script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.