1

I created a custom module, with a button in System > Configuration. Clicking on this button should call a function and then inform the user about the function's results (I suppose by reloading the same page and showing some messages.)

Could you please give me some instructions about how to do that?

system.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <tabs>
        <CustomModules translate="label" module="mymodule">
            <label>CustomModules</label>
            <sort_order>100</sort_order>
        </CustomModules>
    </tabs>
    <sections>
        <CustomModules translate="label" module="mymodule">
            <label>Fix Products</label>
            <tab>CustomModules</tab>
            <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>
                    <fields>
                        <re_enable_configurables translate="label">
                            <label>Click this button to manually fix products.</label>
                            <frontend_type>button</frontend_type>
                            <frontend_model>mymodule/adminhtml_system_config_button</frontend_model>
                            <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>
                        </re_enable_configurables> 
                    </fields>
                </CustomModules_group>
            </groups>
        </CustomModules>
    </sections>
</config>

Block/Adminhtml/System/Config/Button.php

<?php 
class CustomModules_Mymodule_Block_Adminhtml_System_Config_Button extends Mage_Adminhtml_Block_System_Config_Form_Field
{

    protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
    {
        $this->setElement($element);
        $url = Mage::helper('adminhtml')->getUrl("some_kind_of_url_idk");

        $html = $this->getLayout()->createBlock('adminhtml/widget_button')
                    ->setType('button')
                    ->setClass('scalable')
                    ->setLabel('FIX products!')
                    ->setOnClick("setLocation('$url')")
                    ->toHtml();

        return $html;
        $buttonHtml = $this->_getAddRowButtonHtml($this->__('FIX products!'));
        return $buttonHtml;
    }

}
?>
  • you have missing node for group in system.xml for <CustomModules_group> – Piyush Oct 2 '17 at 12:28

Your Answer

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

Browse other questions tagged or ask your own question.