1
我有一個運行在Magento 1.7.0.2上的網站,我需要system.xml文件中的一個自定義按鈕,它允許我從一個類別中刪除所有產品,只有一個單擊。我已經擁有固定的類別ID,因此不需要類別下拉菜單,只需按一下按鈕即可刪除所有產品。我試過使用這個鏈接的答案創建按鈕:Magento - Add a button to system.xml with method attached to it但每次我定義前端模型時,它都會返回一個空白頁面而不是配置頁面。在system.xml中爲Magento 1.7添加一個按鈕
下面是創建按鈕我的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;
}
}
查看此解決方案。這對我很有用: http://magento.stackexchange.com/questions/36169/system-xml-frontend-model-resolve-to-wrong-path – montie 2015-03-06 08:29:54