Nithin
Nithin

Reputation: 543

Magento reading config data

I am trying to read config data for a custom module to enable or disable it based on the config setting. I am trying to read the config data in an Observer like this : $module_state = Mage::helper('stopcheckout')->moduleActive(); and here is my helper. My observer gets called when ever a product is added to cart. But i get a blank page when i try to read the config data with the above snipped of code. Here are the config.xml and system.xml files. Where am i going wrong? Thanks.

Upvotes: 1

Views: 3230

Answers (1)

benmarks
benmarks

Reputation: 23205

Your helper method is not correct, as I'm sure you've guessed :-)

Try this:

<?php
class Foostor_Stopcheckout_Helper_Data extends Mage_Core_Helper_Abstract
{
    /**
     * Check if the extension has been disabled in the system configuration
     */
    public function moduleActive()
    {
        return ! (bool) Mage::getStoreConfigFlag('catalog/stopcheckout/disable_ext');
    }
}

The getStoreConfigFlag() method always returns a boolean. It evaluates the strings "false" and "0" as false, so this is appropriate because the adminhtml/system_config_source_yesno source model uses 1 and 0 as the stored values.

The parameter that is passed for values set via system.xml fields will always have three parts: one for the <sections> node, one for the <groups> node, and one for the <fields> node.

Upvotes: 10

Related Questions