2013-03-19 150 views

回答

1

可以使用安裝腳本

/app/code/local/MagePal/AddCategoryFields/sql/addcategoryfields_setup/upgrade-0.9.5-0.9.8.php

$installer = $this; 

$installer->startSetup(); 

$setup = new Mage_Eav_Model_Entity_Setup('core_setup'); 

$setup->addAttribute('catalog_category', 'magepal_category_fieldname', array(
    'group'   => 'My Tab', 
    'input'   => 'text', 
    'type'   => 'varchar', 
    'label'   => 'Field desc', 
    'backend'  => '', 
    'visible'  => 1, 
    'required'  => 0, 
    'user_defined' => 1, 
    'global'  => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, 
)); 

//$setup->removeAttribute('catalog_category', 'magepal_category_fieldname'); 

$installer->endSetup(); 

請參閱添加類別字段How to add new custom category attribute in Magento

+0

我知道如何添加字段,事情是,我需要先添加我自己的選項卡。 – 2013-03-19 12:51:34

+0

只需更改''group'=>'我的選項卡' – 2013-03-19 12:52:46

+0

它適用於已有的選項卡,但不適用於我創建的選項卡。我沒有覆蓋Mage_Adminhtml_Block_Catalog_Category_Tabs和我使用addTab()的_prepareLayout()方法。 – 2013-03-19 12:59:48

2

要添加一個新的magento類別選項卡(管理類別頁面/管理區域),重寫或簡單地將文件從core/Mage/Adminhtml/Block/Catalog/Category/Tabs.php複製到:local/Mage/Adminhtml /座/目錄/分類/ Tabs.php。

接着在_prepareLayout方法這個代碼後:

$this->addTab(’products’, array(‘label’ => 
Mage::helper(’catalog’)->__(’Category Products’), ‘content’ => 
$this->getLayout()->createBlock(’adminhtml/catalog_category_tab_product’,‘category.product.grid’)->toHtml(),)); 

添加這一個:

$this->addTab(’new_tab’, array(
‘label’ => Mage::helper(’catalog’)->__(’New Category Tab’), 
‘content’ => $this->getLayout()->createBlock(’yourmodule/adminhtml_category_form’)->toHtml(),)); 

參數「內容」指的是一個塊,該塊需要被添加到模塊你正在使用,這裏是塊內容的示例:

<?php class Namespace_Module_Block_Adminhtml_Category_Form extends Mage_Adminhtml_Block_Widget_Form { 
    protected function _prepareForm(){ 
     $form = new Varien_Data_Form(); 
     $this->setForm($form); 
     $fieldset = $form->addFieldset('custom_category_tab_form', array('legend'=>Mage::helper('catalog')->__('Custom Tab')));         $fieldset->addField('anytext', 'text', array('label'=> Mage::helper('catalog')->__('Any Text'),'name'=> 'anytext',)); 
     return parent::_prepareForm();  
     } 
    } 

之後,爲了噸o可以將添加的選項卡字段保存到模塊的表格中,您需要添加一個事件觀察者。將它添加到節中的config.xml文件中的「全局」:

<events> 
    <catalog_category_prepare_save > 
     <observers> 
      <yourmodule> 
       <type>singleton</type> 
       <class> yourmodule /observer</class> 
       <method>categorySave</method> 
      </ yourmodule > 
     </observers> 
    </catalog_category_prepare_save > 
</events> 

並添加觀察者的模型爲「模型」模塊的文件夾:

<?php 
class Namespace_Module _Model_Observer 
{ 
    public function categorySave($observer){ 
    $params = $observer->getRequest()->getParams(); 
    // now you could save your custom category params to your db table 
    } 
} 
相關問題