Magento 读取配置数据

发布于 2024-12-22 23:14:22 字数 485 浏览 1 评论 0原文

我正在尝试读取自定义模块的配置数据,以根据配置设置启用或禁用它。我正在尝试读取 Observer 中的配置数据,如下所示: $module_state = Mage::helper( 'stopcheckout')->moduleActive(); 这是我的 助手。当产品添加到购物车时,我的观察者就会接到电话。但是当我尝试使用上面的代码片段读取配置数据时,我得到一个空白页。以下是 config.xmlsystem.xml 文件。我哪里出错了?谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

原谅我要高飞 2024-12-29 23:14:22

您的辅助方法不正确,我相信您已经猜到了:-)

尝试一下:

<?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');
    }
}

getStoreConfigFlag() 方法始终返回一个布尔值。它将字符串“false”和“0”评估为 false,因此这是合适的,因为 adminhtml/system_config_source_yesno 源模型使用 1 和 0 作为存储值。

通过 system.xml 字段设置的值传递的参数始终包含三部分:一部分用于 节点,一部分用于 节点,一个用于 节点。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文