Magento 1 – How to Get Data from config.xml of a Module

configurationcore-config-datamodulexml

In the module A I need to get some data from file config.xml of modules B and C.
Are there any methods or classes dedicated for this?

Especialy I need to get XML structure and values of node <default> so that I can restore default values of system configuration of modules B and C. Below is example from config.xml of Wishlist module:

<config>
    <default>
        <wishlist>
            <general>
                <active>1</active>
            </general>
            <email>
                <email_identity>general</email_identity>
                <email_template>wishlist_email_email_template</email_template>
            </email>
        </wishlist>
    </default>
</config>

As far as I know Magento loads config.xml files of all modules, so I was wondering maybe this data is already cached and can be retrieved from cache somehow? If not, how to retrieve it programaticaly?

Best Answer

You can get a certain node from the config like this.

$value = Mage::getConfig()->getNode('default/wishlist/general/active');

this should retrive the value of

<default>
    <wishlist>
        <general>
            <active>1</active> <!-- this value -->
        </general>
    </wishlist>
</default>

The problem is that it does not retrieve the value from a specific file. it gets the value from the merged config.

If you want values from a specific file, do this.

$configFile = Mage::getConfig()->getModuleDir('etc', 'Mage_Wishlist').DS.'config.xml';
$string = file_get_contents($configFile);
$xml = simplexml_load_string($string, 'Varien_Simplexml_Element');

You will have in the $xml variable the loaded xml file and your can use xpath to find a specific node.

Related Topic