3

I have been following another excellent article by Mr Storm: http://alanstorm.com/custom_magento_system_configuration

However, I've hit a snag. In the admin system config, I have an existing tab that is part of a local module I created.

The tab is created with the following code (app/code/local/Jongosi/Adminhtml/etc/system.xml):

<config>
    <tabs>
        <jongosi module="adminhtml">
            <label>Jongosi</label>
            <sort_order>999</sort_order>
        </jongosi>
    </tabs>
</config>

In subsequent modules that I create locally, I would like to add items to the existing (jongosi) tab.

I'm using the following code (app/code/local/Jongosi/Module/etc/system.xml):

<config>
    <sections>
        <jongosi_module_options translate="label" module="jongosi_module">
            <label>Jongosi Module Options</label>
            <tab>jongosi</tab>
            <frontend_type>text</frontend_type>
            <sort_order>1000</sort_order>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>1</show_in_store>
            <groups>
                <module translate="label">
                    <label>Module Options</label>
                    <frontend_type>text</frontend_type>
                    <sort_order>1</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>1</show_in_store>                
                    <fields>
                        <brands translate="label">
                            <label>Brands Enabled</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                            <sort_order>1</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                            <comment>Enable or disable brands.</comment>
                        </brands>
                    </fields>
                </module>
            </groups>
        </jongosi_module_options>
    </sections>
</config>

The tab shows up fine with the items listed one below another, but clicking the links ends in a 404. I have cleared the cache many times (rm -rf var/cache/*) , re-indexed and logged out and in again.

My ACL code looks as follows (app/code/local/Jongosi/Module/etc/adminhtml.xml):

<config>
    <adminhtml>
        <acl>
            <resources>
                <admin>
                    <children>
                        <system>
                            <children>
                                <config>
                                    <children>
                                        <jongosi_module_options>
                                            <title>Jongosi Module</title>
                                        </jongosi_module_options>
                                    </children>
                                </config>
                            </children>
                        </system>
                    </children>
                </admin>
            </resources>
        </acl>
    </adminhtml>
</config>

How can I get this to work? Thanks!

6

Assuming you mean the 404 page where there's admin chrome and 404 text in the content area, it sounds like your ACL is setup incorrectly or your current user account lacks the proper ACL credentials to view your new System Configuration section.

First, if your user has the all ACL permissions (i.e. is a system root user and/or the default user created during setup), you'll need to clear your admin session before being able to see the page. Magento caches the individual permissions an admin user has in the session, not the cache. This happens when you login — so your new ACL rule hasn't been added to the list of rules allowed by your user.

Second, it's always best to go right to the source of an error. Take a look at the following section of code.

#File: app/code/core/Mage/Adminhtml/controllers/System/ConfigController.php
protected function _isSectionAllowed($section)
{
    try {
        $session = Mage::getSingleton('admin/session');
        $resourceLookup = "admin/system/config/{$section}";
        if ($session->getData('acl') instanceof Mage_Admin_Model_Acl) {
            $resourceId = $session->getData('acl')->get($resourceLookup)->getResourceId();
            if (!$session->isAllowed($resourceId)) {
                throw new Exception('');
            }
            return true;
        }
    }
    catch (Zend_Acl_Exception $e) {
        $this->norouteAction();
        $this->setFlag('', self::FLAG_NO_DISPATCH, true);
        return false;
    }
    catch (Exception $e) {
        $this->deniedAction();
        $this->setFlag('', self::FLAG_NO_DISPATCH, true);
        return false;
    }
}

This is what triggers a 404 page if you're missing an ACL role. A

var_dump($e->getMessage());
var_dump($resourceLookup);

in each of the catch blocks will tell you why Magento thinks your user doesn't have the right access permissions.

  • Thank you Alan, that pointed me in the right direction. Resource was not found, but when I moved my adminhtml.xml contents to the config.xml, all is well. I'm using Magento 1.7.0.2 CE; I thought adminhtml.xml was an approved practice? – Jongosi Jul 24 '13 at 8:58
  • 1
    @Jongosi Ah, re-reading your question that makes sense. When you drop things in adminhtml.xml, you don't need/want the surrounding adminhtml tag. See one of the shipping file for an example of the correct structure (./Mage/Checkout/etc/adminhtml.xml) – Alan Storm Jul 24 '13 at 15:58
  • Thank you Alan, had a look and I can see what you mean. Thx for following up. – Jongosi Jul 24 '13 at 16:51
  • 1
    Related note: you can programatically clear the session's ACL cache: magento.stackexchange.com/a/31480/335 – Colin O'Dell Aug 6 '14 at 21:21
0

Add this code to your custome modules system.xml

This code displayed in system->config->catalog tab->catalog

<sections>
    <catalog translate="label" module="catalog">
        <show_in_store>1</show_in_store>
        <groups>
            <logincatalog translate="label">
                <label>Login Only Catalog</label>
                <sort_order>765</sort_order>
                <show_in_default>1</show_in_default>
                <show_in_website>1</show_in_website>
                <show_in_store>1</show_in_store>
                <fields>
                    <disable_ext translate="label">
                        <label>Disable Extension</label>
                        <frontend_type>select</frontend_type>
                        <source_model>adminhtml/system_config_source_yesno</source_model>
                        <sort_order>10</sort_order>
                        <show_in_default>1</show_in_default>
                        <show_in_website>1</show_in_website>
                        <show_in_store>1</show_in_store>
                    </disable_ext>
                    <hide_categories translate="label">
                        <label>Hide Category Navigation</label>
                        <frontend_type>select</frontend_type>
                        <source_model>adminhtml/system_config_source_yesno</source_model>
                        <sort_order>20</sort_order>
                        <show_in_default>1</show_in_default>
                        <show_in_website>1</show_in_website>
                        <show_in_store>1</show_in_store>
                    </hide_categories>
                    <message translate="label">
                        <label>Message when a customer is redirected to login page</label>
                        <frontend_type>text</frontend_type>
                        <sort_order>30</sort_order>
                        <show_in_default>1</show_in_default>
                        <show_in_website>1</show_in_website>
                        <show_in_store>1</show_in_store>
                    </message>
                </fields>
            </logincatalog>
        </groups>
    </catalog>
</sections>
0

Resolved. There is very small mistake: I have created a module 'Tabdemo' using Namespace 'Jongosi'.

There is Tab created with the following code:

app/code/local/Jongosi/Tabdemo/etc/system.xml

<config>
<tabs>
    <jongosi translate="label" module="tabdemo">
        <label>Jongosi</label>
        <sort_order>999</sort_order>
    </jongosi>
</tabs>
<sections>
    <jongosi_module_options translate="label" module="tabdemo">
        <label>Jongosi Module Options</label>
        <tab>jongosi</tab>
        <frontend_type>text</frontend_type>
        <sort_order>1000</sort_order>
        <show_in_default>1</show_in_default>
        <show_in_website>1</show_in_website>
        <show_in_store>1</show_in_store>
        <groups>
            <module translate="label">
                <label>Module Options</label>
                <frontend_type>text</frontend_type>
                <sort_order>1</sort_order>
                <show_in_default>1</show_in_default>
                <show_in_website>1</show_in_website>
                <show_in_store>1</show_in_store>               
                <fields>
                    <brands translate="label">
                        <label>Brands Enabled</label>
                        <frontend_type>select</frontend_type>
                        <source_model>adminhtml/system_config_source_yesno</source_model>
                        <sort_order>1</sort_order>
                        <show_in_default>1</show_in_default>
                        <show_in_website>1</show_in_website>
                        <show_in_store>1</show_in_store>
                        <comment>Enable or disable brands.</comment>
                    </brands>
                </fields>
            </module>
        </groups>
    </jongosi_module_options>
</sections>       

In my above code check value for attr 'module' i have used (i.e. module name).

app/code/local/Jongosi/Tabdemo/etc/adminhtml.xml

<config>
<acl>
    <resources>
        <admin>
            <children>
                <system>
                    <children>
                        <config>
                            <children>
                                <jongosi_module_options>
                                        <title>Jongosi Module</title>
                                </jongosi_module_options>
                            </children>
                        </config>
                    </children>
                </system>
            </children>
        </admin>
    </resources>
</acl>

Do not need to use adminhtml tag immediate after config tag.

app/code/local/Jongosi/Tabdemo/etc/config.xml

1.0.0

<global>
    <helpers>
        <tabdemo>
            <class>Jongosi_Tabdemo_Helper</class>
        </tabdemo>
    </helpers>
</global>

Do not forget to create Helper Class also

class Jongosi_Tabdemo_Helper_Data extends Mage_Core_Helper_Abstract
{


}

What i found mistake was in adminhtml.xml with adminhtml tag as well as check system.xml minutely.
Don't forgot to logout and login to see the reflection.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.