关于模块:如何将扩展程序添加到Magento管理员菜单侧边栏?

How to add my extension to Magento Admin Menu Sidebar?

我正在创建我的第一个社区扩展。这是一个非常简单的方法,并且已经可以使用了。我想学习如何将扩展名添加到管理区域,以允许客户禁用或启用它。我需要添加到模块中才能执行此操作?任何帮助都会很棒!

这是我的代码:

app / etc / modules / config.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
    <Module_Name>

        <!-- Whether our module is active: true or false -->
        true</active>

        <!-- Which code pool to use: core, community or local -->
        <codePool>community</codePool>

    </Module_Name>
</modules>
</config>

etc / system.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?xml version="1.0"?>
<config>
<sections>
    <module translate="label" module="modulename">
        <label>Your Module Name</label>
        <tab>tab_id_where_you_want_to_add_your_section</tab>
        <frontend_type>text</frontend_type>
        <sort_order>980</sort_order>
        <show_in_default>1</show_in_default>
        <show_in_website>1</show_in_website>
        <show_in_store>0</show_in_store>
        <groups>
            <modulename>
                <label>Your Group Title</label>
                <sort_order>10</sort_order>
                <show_in_default>1</show_in_default>
                <show_in_website>1</show_in_website>
                <show_in_store>0</show_in_store>
                <fields>
                    <comment translate="label comment">    
                        <label>Your Field Title</label>
                        <comment>Your Comment</comment>    
                        <frontend_type>text</frontend_type>
                        <sort_order>10</sort_order>
                        <show_in_default>1</show_in_default>
                        <show_in_website>1</show_in_website>
                        <show_in_store>0</show_in_store>
                    </comment>
                </fields>
            </modulename>
        </groups>
    </your_module>
</sections>
</config>

etc / adminhtml.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?xml version="1.0" encoding="UTF-8"?>
<config>
<menu>
    <modulename translate="title" module="shipping">
        Module
        <sort_order>15</sort_order>
        <children>
            <modulename translate="title" module="modulename">
                Drop Down Shipping
                <sort_order>1</sort_order>
                adminhtml/shipping/index</action>
            </example>
        </children>
    </modulename>
</menu>

    <layout>
        <updates>
            <modulename>
                <file>shipping.xml</file>
            </modulename>
        </updates>
    </layout>
 
    <resources>
       
            <children>
                <system>
                    <children>
                        <config>
                            <children>
                                <modulename translate="title" module="shipping">
                                    Your Module Name
                                </modulename>
                            </children>
                        </config>
                    </children>
                </system>
            </children>
        </admin>
    </resources>
  </acl>

</config>

etc / config.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?xml version="1.0" encoding="UTF-8"?>

<config>
<modules>
    <Module_Name>

        <version>0.0.1</version>

    </Module_Name>

</modules>

<frontend>
    <layout>
        <updates>
            <modulename>
                <file>shipping.xml</file>
            </modulename>
        </updates>
    </layout>
</frontend>

<global>
    <helpers>
        <modulename>
            <class>Module_Name_Helper</class>
        </modulename>
    </helpers>
</global>

</config>

我的主题布局XML文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?xml version="1.0"?>

<layout version="0.1.0">

<checkout_cart_index>
<reference name="head">
    <stylesheet>css/module/shipping.css</stylesheet></action>
</reference>
<reference name="checkout.cart.shipping">
 <template>module/shipping.phtml</template></action>
</reference>
</checkout_cart_index>

</layout>

Helper / Data.php

1
2
3
4
5
6
<?php

class Module_Name_Data extends Mage_Core_Helper_Abstract
{

}

启用和禁用模块功能已在系统>>配置>>高级>>高级中。

顺便说一句,如果您想在"系统>>配置"页面中添加菜单,本文可能会为您提供http://alanstorm.com/custom_magento_system_configuration。

如果遇到错误,请再次检查一切是否正常。


您是否想将节点添加到主管理菜单(带弹出子菜单的水平管理菜单)或System\\Configuration屏幕的侧边栏菜单尚不清楚。以下是如何将部分,组和字段添加到Magento配置屏幕的说明。

首先,您需要将etc/system.xml文件添加到模块中:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?xml version="1.0"?>
<config>
    <sections>
        <your_module translate="label" module="your_module_shortcode">
            <label>Your Module Name</label>
            <tab>tab_id_where_you_want_to_add_your_section</tab>
            <frontend_type>text</frontend_type>
            <sort_order>980</sort_order>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>0</show_in_store>
            <groups>
                <your_group_name>
                    <label>Your Group Title</label>
                    <sort_order>10</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>0</show_in_store>
                    <fields>
                        <your_field_name translate="label comment">    
                            <label>Your Field Title</label>
                            <comment>Your Comment</comment>    
                            <frontend_type>text</frontend_type>
                            <sort_order>10</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </your_field_name>
                    </fields>
                </your_group_name>
            </groups>
        </your_module>
    </sections>
</config>

,然后将以下部分添加到您的etc/adminhtml.xml中。它将您新创建的部分添加到ACL中,因此您将能够控制可以访问它的管理员角色:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<config>
   
        <resources>
           
                <children>
                    <system>
                        <children>
                            <config>
                                <children>
                                    <your_module translate="title" module="your_module_shortcode">
                                        Your Module Name
                                    </your_module>
                                </children>
                            </config>
                        </children>
                    </system>
                </children>
            </admin>
        </resources>
    </acl>
</config>