Magento Expert Forum - Improve your Magento experience

Results 1 to 4 of 4

Customizing Magento System Configuration. Part 2

  1. #1
    Junior Member ccvv's Avatar
    Join Date
    Mar 2013
    Posts
    66
    Thanks
    6
    Thanked 17 Times in 13 Posts

    Default Customizing Magento System Configuration. Part 2

    Before reading this tutorial please check these tutorials if you has not read yet:

    Magento system settings overview

    Customizing Magento System Configuration. Part 1

    Today we will customize tabs and sections, groups and fields without using system.xml.

    Certainly, we know that Magento has a great event system and this knowledge will help us to make changes in the System Configuration.

    For our purposes, we will create a new module and call it ‘SystemConfig’. It consists of three files. First of them is for initialing our module:
    app/etc/modules/Atwix_SystemConfig.xml

    HTML Code:
    <?xml version="1.0"?>
    <config>
        <modules>
            <Atwix_SystemConfig>
                <active>true</active>
                <codePool>local</codePool>
            </Atwix_SystemConfig>
        </modules>
    </config>
    Afterwards, we need to create module configuration file. That is the second one:
    app/code/local/Atwix/SystemConfig/etc/config.xml
    HTML Code:
    <?xml version="1.0"?>
    <config>
        <modules>
            <Atwix_SystemConfig>
                <version>1.0.0</version>
            </Atwix_SystemConfig>
        </modules>
        <global>
            <models>
                <atwix_systemconfig>
                    <class>Atwix_SystemConfig_Model</class>
                </atwix_systemconfig>
            </models>
            <events>
                <adminhtml_init_system_config>
                    <observers>
                        <atwix_init_system_config>
                            <class>atwix_systemconfig/observer</class>
                            <method>changeSystemConfig</method>
                        </atwix_init_system_config>
                    </observers>
                </adminhtml_init_system_config>
            </events>
        </global>
    </config>
    However, let’s check what we have now. So, in the configuration file we define model, configure event, and also, the event ‘adminhtml_init_system_config’ which makes possible to work with System Configuration data.

    And, the third one, the last file – it is an observer, where we do all the magic: app/code/local/Atwix/SystemConfig/Model/Observer.php

    PHP Code:
    <?php
     
    class Atwix_SystemConfig_Model_Observer
    {
        public function 
    changeSystemConfig(Varien_Event_Observer $observe)
        {
            
    $config $observe->getConfig();
     
            return 
    $this;
        }
    }
    Okey, we put debug breakpoint to the line with the return statement and have a good inspect of the picture being used:



    Check this out!

    In the config, there are all the tabs and sections, and in the section – groups and fields, but what about to try some changes. For example, let’s change sort order and label for ‘advanced’ tab and add a comment to the ‘Startup Page’ field.

    Thuswise, at first – change code in the observer: app/code/local/Atwix/SystemConfig/Model/Observer.php


    PHP Code:
    <?php
     
    class Atwix_SystemConfig_Model_Observer
    {
        public function 
    changeSystemConfig(Varien_Event_Observer $observer)
        {
            
    //get init sections and tabs
            
    $config $observer->getConfig();
     
            
    //get tab 'advanced', change sort order and label
            
    $advancedTab $config->getNode('tabs/advanced');
            
    $advancedTab->sort_order 1;
            
    $advancedTab->label .= ' (on top)';
     
            
    //get field 'page', add comment
            
    $config->getNode('sections/admin/groups/startup/fields/page')->comment 'after successful login you will see this page';
     
            return 
    $this;
        }
    }


    Great, advanced tab on the top!

    After what, it is possible to make a lot of changes.

    Moreover, we can also create tabs and section, group and field, besides that, using Mage_Core_Model_Config_Element class we are able to work with elements: create, edit, append, extend, etc. And the next example shows us how to add a new group with the fields to the ‘admin’ section. In this case, the observer should have the following code: app/code/local/Atwix/SystemConfig/Model/Observer.php

    PHP Code:
    <?php
     
    class Atwix_SystemConfig_Model_Observer
    {
        public function 
    changeSystemConfig(Varien_Event_Observer $observer)
        {
            
    //get init sections and tabs
            
    $config $observer->getConfig();
     
            
    //get tab 'advanced', change sort order and label
            
    $advancedTab $config->getNode('tabs/advanced');
            
    $advancedTab->sort_order 1;
            
    $advancedTab->label .= ' (on top)';
     
            
    //get field 'page', add comment
            
    $config->getNode('sections/admin/groups/startup/fields/page')->comment 'after successful login you will see this page';
     
            
    //add new group with fields in section 'admin'
            
    $adminSectionGroups $config->getNode('sections/admin/groups');
            
    $new_group_xml = new Mage_Core_Model_Config_Element('
                <atwix_new_group>
                    <label>New Group</label>
                    <sort_order>99</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_message>
                                <label>Disable Message</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_message>
                            <message>
                                <label>Message</label>
                                <frontend_type>text</frontend_type>
                                <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>
                                <depends>
                                    <disable_message>0</disable_message>
                                </depends>
                            </message>
                    </fields>
                </atwix_new_group>
            '
    );
            
    $adminSectionGroups->appendChild($new_group_xml);
     
            return 
    $this;
        }
    }


    But, if we wish it is possible to implement a lot of things and reinvent the wheel =)

    At the same time, it will be highly helpful to make some changes in the System Configuration while using the observer.

    Source: Atwix

    View more threads in the same category:


  2. #2
    New member
    Join Date
    May 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    HI All,

    How can i add post a thread here??

    Can anyone post URL TO POST THREAD here for me so i can post a thread???

  3. #3
    New member
    Join Date
    May 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I have a store, I am using "Subscribe aheadworks extension" to create subscription products. For recurring payment, i am using paypal pro. Now i want to send invoice on each occurrence of payment. Please help me out on this.

  4. #4
    Administrator david's Avatar
    Join Date
    Nov 2012
    Posts
    260
    Thanks
    23
    Thanked 40 Times in 33 Posts

    Default

    Quote Originally Posted by Er Gazzy View Post
    I have a store, I am using "Subscribe aheadworks extension" to create subscription products. For recurring payment, i am using paypal pro. Now i want to send invoice on each occurrence of payment. Please help me out on this.
    Hi Er Gazzy, to make sure we have a very high quality of "Documents and Tutorial" part of this forum. This part category is limited only for mod and admin can add new thread. To add new thread for any question, please use this category http://magentoexpertforum.com/forumd...ming-Questions

    Thanks and sorry for this inconvenience.

Similar Threads

  1. Magento Module Development - Part 5 - System.xml and Module
    By rocker in forum Programming & Development
    Replies: 1
    Last Post: 28-11-2017, 08:41 AM
  2. Customizing Transactional Emails for Magento
    By golddev in forum Webmaster & Administrator
    Replies: 0
    Last Post: 02-07-2013, 01:09 PM
  3. Magento Module Development - Part 6 - System.xml Advance and Module
    By rocker in forum Programming & Development
    Replies: 1
    Last Post: 29-05-2013, 01:10 PM
  4. Customizing Magento System Configuration. Part 1
    By ccvv in forum Programming & Development
    Replies: 0
    Last Post: 17-05-2013, 03:14 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •