开发者

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

  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.

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->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 ...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜