【问题标题】:Add a Button in system.xml for Magento 1.7在 System.xml 中为 Magento 1.7 添加一个按钮
【发布时间】: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;
    }
  }

【问题讨论】:

标签: php xml magento magento-1.7


【解决方案1】:

您必须在 Button.php 中为前端模型定义模板

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

本文可能会帮助您完成您的模块。 -->> http://www.atwix.com/magento/add-button-to-system-configuration/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多