Sankar Subburaj
Sankar Subburaj

Reputation: 5042

What is getConfigData?

What is getConfigData? and diff between getConfigData and getStoreConfigData in Magento.

$this->getConfigData('shippingspecificcountry', $store_id);

I tried with my current store id and 0, both gives empty array.

Can anyone explain about the above method.

Upvotes: 0

Views: 2337

Answers (1)

Alana Storm
Alana Storm

Reputation: 166106

Your question could use a little more context -- lacking that.

The Mage::getStoreConfig method is a static method on the global Mage class, and provides access to configuration values stored in Magento's Configuration tree. Magento's configuration tree is created by

  1. Loading all XML files in app/etc/*.xml
  2. Loading all XML files from `app/etc/modules/*.xml'
  3. Merging all the config.xml files from the active modules
  4. Merging in any values set in core_config_data (via System -> Configuration in the admin)

Because Magento's configuration is so big, many module developers add methods like getConfigData or getConfig to make fetching specific configuration values easy. For example, consider this oversimplified example

Mage::getStoreConfig('foo/baz/bar')

vs.

$this->getConfig('bar');

....
public function getConfigData($key)
{
    return Mage::getStoreConfig('foo/baz/' . $bar);
}

The second allows a client programmer more concise code.

You can see an example of this in the base class for Magento's various shipping carriers

public function getConfigData($field)
{
    if (empty($this->_code)) {
        return false;
    }
    $path = 'carriers/'.$this->_code.'/'.$field;
    return Mage::getStoreConfig($path, $this->getStore());
}

Here the getConfigData method will automatically look for the configuration key in the carriers node -- using the carrier's _code as a sub-node, and checking the instantiated carrier object for a store code.

The getConfigData method will behave differently depending on which class/object you're using, but hopefully that's enough to get you pointed in the right direction.

Upvotes: 5

Related Questions