【发布时间】:2015-03-03 01:45:08
【问题描述】:
我有一个在 Magento 1.7.0.2 上运行的网站,我需要在 system.xml 文件中添加一个自定义按钮,让我只需单击一下即可从一个类别中删除所有产品。我已经有了固定的类别 ID,因此不需要类别下拉列表,只需一个按钮即可删除所有产品。我尝试使用此链接中的答案创建按钮:Magento - Add a button to system.xml with method attached to it 但每次我定义前端模型时,它都会返回一个空白页面而不是配置页面。
这是我用于创建按钮的 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;
}
}
【问题讨论】:
-
查看此解决方案。这对我很有用:magento.stackexchange.com/questions/36169/…
标签: php xml magento magento-1.7