4

In magento backend admin panel system->configuration->Main Website->Sales->Shipping Methods->Table Rates we have "export csv" which is downloading a file. like the same I have placed a export button my group. now how can we add action to this export button and download a file. I have placed export button in system.xml with

<export translate="label">
<label>export</label>
  <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>
  <frontend_type>export</frontend_type>
</export>
7

The class that handles that button is Mage_Adminhtml_Block_System_Config_Form_Field_Export. and it has the url in one of the methods, so you cannot use <frontend_type>export</frontend_type> for your custom button. You have to create a new field renderer similar to Mage_Adminhtml_Block_System_Config_Form_Field_Export and add your url in there.
Try it like this:

<?php
class [Namespace]_[Module]_Block_Adminhtml_System_Config_Custombutton extends Mage_Adminhtml_Block_System_Config_Form_Field  implements Varien_Data_Form_Element_Renderer_Interface{
    protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
    {
        $buttonBlock = Mage::app()->getLayout()->createBlock('adminhtml/widget_button');

        $params = array(
            'website' => $buttonBlock->getRequest()->getParam('website')
        );

        $data = array(
            'label'     => Mage::helper('adminhtml')->__('Do Something'),
            'onclick'   => 'setLocation(\''.Mage::helper('adminhtml')->getUrl("*/controller/action", $params) . '\' )',
            'class'     => '',
        );

        $html = $buttonBlock->setData($data)->toHtml();

        return $html;
    }
}

and your system.xml section should look like this

<export translate="label">
    <label>Some button</label>
    <sort_order>1</sort_order>
    <type>button</type>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>1</show_in_store>
    <frontend_model>[module]/adminhtml_system_config_custombutton</frontend_model>
</export>
  • Hi Marius, Thanks for the above description .Can you Please provide the Controller code so when i cleck on button something should download – Magento AJ Feb 26 '15 at 6:32

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.