[英]Add a Button in system.xml for Magento 1.7
我有一个在Magento 1.7.0.2上运行的网站,并且我需要在system.xml文件中使用一个自定义按钮,该按钮使我只需单击一下即可删除该类别中的所有产品。 我已经有了固定的类别ID,因此不需要类别下拉菜单,只需单击一个按钮即可删除所有产品。 我尝试使用此链接中的答案来创建按钮: Magento-向system.xml添加一个按钮,并附加方法,但是每次定义前端模型时,它都会返回一个空白页面而不是Configuration页面。
这是我用于创建按钮的system.xml代码:
<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>
这是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;
}
}
您必须在Button.php中为前端模型定义模板
protected function _construct()
{
parent::_construct();
$this->setTemplate('diy/button.phtml');
}
本文可能会帮助您完成模块。 ->> http://www.atwix.com/magento/add-button-to-system-configuration/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.