简体   繁体   中英

Add a Button in system.xml for Magento 1.7

I have a website running on Magento 1.7.0.2 and I need a custom button in the system.xml file that will allow me to delete all the products from a category with just one click. I already have the fixed category ID so there's no need for a category dropdown, just a button what will delete all the products. I've tried creating the button using the answer from this link: Magento - Add a button to system.xml with method attached to it but every time I define the frontend model it returns a blank page instead of the Configuration page.

Here's my system.xml code for creating the button:

<productdelete>
     <label>Delete Customer Generated Products</label>
     <frontend_type>text</frontend_type>
     <sort_order>20</sort_order>
     <show_in_default>1</show_in_default>
     <show_in_website>0</show_in_website>
     <show_in_store>1</show_in_store>
                <fields>
                    <productdeletebutton translate="label">
                        <label>Delete Now</label>
                        <frontend_type>button</frontend_type>
                        <frontend_model>diy/button</frontend_model>
                        <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>
                    </productdeletebutton>
                </fields>
</productdelete>

And here's my code for the Button.php:

  class CT_Diy_Block_Button extends Mage_Adminhtml_Block_System_Config_Form_Field
  {

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

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

      return $html;
    }
  }

You have to define tempate for frontend model in Button.php

protected function _construct()
{
    parent::_construct();
    $this->setTemplate('diy/button.phtml');
}

This article may help you to complete your module. -->> http://www.atwix.com/magento/add-button-to-system-configuration/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM