1

I am Adding Custom Section in System->Config Tab.

I need to add Button as Field and its related action which I need to perform. But I cannot find on google for button all example provide other field option but hard to get button example.

Other Section Working fine but I am not able to add button and related action (filepath) which call on click.

<fields> 
  <goldprice translate="label"> 
    <label>GoldPrice</label>                   
    <frontend_type>text</frontend_type>                
    <sort_order>0</sort_order>  
    <show_in_default>1</show_in_default> 
    <show_in_website>1</show_in_website> 
    <show_in_store>1</show_in_store> 
    <comment>Gold Price per 1gm</comment> 
  </goldprice> 
  <run translate="label">
    <frontend_type>button</frontend_type>
    <frontend_model>/adminhtml_system_config_customfield</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>
  </run> 
</fields>

My Config File Like Below

<?xml version="1.0"?>
<config>
  <modules>
    <LetsNurture_CustomGrid>
      <version>0.1.0</version>
    </LetsNurture_CustomGrid>
  </modules>
  <global>
    <blocks>
      <customgrid>
        <class>LetsNurture_CustomGrid_Block</class>
      </customgrid>
    </blocks>
    <models>
      <class>LetsNurture_CustomGrid_Model</class>
    </models>
    <helpers>
      <customgrid>
        <class>LetsNurture_CustomGrid_Helper</class>
      </customgrid>
    </helpers>
    <events>
      <admin_system_config_changed_section_gold> <!-- identifier of the event we want to catch -->
        <observers>
          <customgrid>
            <type>model</type>
            <class>LetsNurture_CustomGrid_Model_Observer</class>
            <method>UpdatePrice</method>
          </customgrid>
        </observers>
      </admin_system_config_changed_section_gold>
    </events>
  </global>
</config>

And Customfiled.php like below

class LetsNurture_CustomGrid_Block_Adminhtml_System_Config_Customfield extends Mage_Adminhtml_Block_System_Config_Form_Field
{
    protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
    {
        $url = $this->getUrl('catalog/product'); //

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


        return $html;
    }
}

But it gives me Warning like this "failed to open stream: No such file or directory"

Thanks, Yogesh

2

<frontend_model> path goes to to Blocks (instead of Models).

Incidentally, even though it’s named a model class but we have to create it as a Magento Block class since this is how the other built in front end model classes are implemented.

As well as, it is used for template output so it’s appropriate to create a block class for this.

Example

<frontend_model>NAMESPACE_MODULENAME/adminhtml_system_config_customfield</frontend_model>

So

Create Customfield.php under .../NAMESPACE/MODULENAME/Block/Adminhtml/System/Config/ with the following content:

class NAMESPACE_MODULENAME_Block_Adminhtml_System_Config_Customfield extends Mage_Adminhtml_Block_System_Config_Form_Field
{


    protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
    {       
        $html = parent::_getElementHtml($element);
       //Write your custom html here
        return $html;
    }
}

Hope this help you

  • getting this error Warning: include(Mage/LetsNurture/CustomGrid/Block/Adminhtml/System/Config/Customfield.php): failed to open stream: No such file or directory ( I dont know why its searching in core even this placed in local) – Yogesh Oct 21 '15 at 10:06
  • Please add following under global tag in config.xml: <blocks> <Mymodule> <class>Mynamespace_Mymodule_Block</class> </Mymodule> </blocks> – Keyur Shah Oct 21 '15 at 10:16
  • I have Added that But Even this is happening – Yogesh Oct 21 '15 at 10:25
  • Is your cimpilation is disbaled ? If not then disbale it and try,,And have you clear your cache ? – Keyur Shah Oct 21 '15 at 10:29
  • Thanks for Help, I will Try and reply because by now working on other. – Yogesh Oct 21 '15 at 10:37

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.