get magento module config data in Observer
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
- Company/Modulename/etc/config.xml
- Company/Modulename/etc/system.xml
- 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.
us开发者_高级运维ing $this->getConfigData(’password’); gives a
Call to undefined method
error Any suggestions?
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
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
In a shipment module I can use $this->getConfigDat
a 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 ...
精彩评论