11
votes

I created a module with an observer for the sales module with event hook ‘sales_order_shipment_save_after’ ,

My module has the following files

  1. Company/Modulename/etc/config.xml
  2. Company/Modulename/etc/system.xml
  3. Company/Modulename/Model/Observer.php

there are four fields in the modules admin configuration fields I want to get those saved data in the Observer class.

using $this->getConfigData(’password’); gives a

Call to undefined method

error Any suggestions?

3

3 Answers

38
votes

Magento uses a static method on the global Mage application object to get configuration values

$config = Mage::getStoreConfig('section_name/group/field'); //value
$config = Mage::getStoreConfig('section_name/group'); //array
3
votes

An amendment to Alan's completely correct answer.

Along with path as first parameter, getStoreConfig also accepts storeid as second parameter(optional).

Well, this is useful when you want to retrieve store-wise values.

Alan has mentioned this point in his own tutorial. I guess, he has not mentioned here just because OP has not mentioned this requirement in his question.

Please refer this

0
votes

In a shipment module I can use $this->getConfigData for fields in system.xml, but in another kind of modules sometimes not, e.g. extends Mage_Core_Model_Abstract, than I must use getStoreConfig. So the answer is you don't have to use always getStoreConfig. But I don't know why ...

Answer: getConfigData is just defined in a shipment class and uses getStoreConfig too. A little confusing that some functions are extra defined and unneeded in fact ...