14

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?

20

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.

  • The value could be retrieved from the DB if it is defined in the column path in core_config_data, too. But only in the XML's config files (this are the defaults) – Victor Aguilar Jul 21 '17 at 22:38
6

You can access the config.xml of any module through Mage::getConfig. All XMLs are merged into one string so you can't really specify the exact module but you can filter on tags path.

$default_xml = Mage::getConfig()
   ->loadModulesConfiguration('config.xml')
   ->getNode('default/wishlist')
   ->asXML(); 

You might need to add a dependency in module A on module B and C to make sure their config.xml is loaded when you're executing above code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.