我在System-> Configuration-> Design下创建了自定义组和字段 我使用了以下事件。

<admin_system_config_changed_section_design>
    <observers>
        <custom>
            <type>singleton</type>
            <class>Custon_Custom_Observer</class>
            <method>save</method>
            </custom>
    </observers>
</admin_system_config_changed_section_design>
.

在magento中有三种类型的范围。

1)默认

2)网站

3)存储

我希望管理面板中我自定义字段的所有值存储自定义表中的值。

例如, 您在商店级别获取描述字段值。

Mage::getStoreConfig('design/custom/description');
.

我想要网站级别和当前商店级别的上述值。 我尝试了这个链接

有帮助吗?

解决方案

在config.xml中,

 <global>
    <events>
        <admin_system_config_changed_section_design>
            <observers>
                <custom>
                    <type>singleton</type>
                    <class>Custon_Custom_Observer</class>
                    <method>saveSystemConfig</method>
                    </custom>
            </observers>
        </admin_system_config_changed_section_design>
    </events>
 </global>
.

在Observer.php中,

public function saveSystemConfig(Varien_Event_Observer $observer)
{
    $postData = $observer->getEvent()->getData();

    if (is_null($postData['store']) && $postData['website']) //check for website scope
    {
        $scopeId = Mage::getModel('core/website')->load($postData['website'])->getId();
        $description  = Mage::app()->getWebsite($scopeId)->getConfig('design/custom/description');
        $currentScope = 'websites';
    }
    elseif($postData['store']) //check for store scope
    {
        $scopeId =   Mage::getModel('core/store')->load($postData['store'])->getId();
        $description  = Mage::app()->getStore($scopeId)->getConfig('design/custom/description');
        $currentScope = 'stores';
    }
    else //for default scope
    {
        $scopeId = 0;
        $description  = Mage::getStoreConfig('design/social-meta-tags/design/custom/description')
        $currentScope = 'default';
    }
}
.

从上面,您可以在所有范围内获取单个字段值。

许可以下: CC-BY-SA归因
scroll top