Answers:
我个人会去布局/动作方式使用addTab()
提供Mage_Adminhtml_Block_Widget_Tabs
因此,这里涉及2个主要动作:
-1.版面变更-
<?xml version="1.0"?>
<layout>
<adminhtml_catalog_product_edit>
<reference name="product_tabs">
<block type="MODULENAME/adminhtml_catalog_product_edit_tab" name="custom_tab"/>
<action method="addTab">
<name>Custom Tab</name>
<block>custom_tab</block>
</action>
</reference>
</adminhtml_catalog_product_edit>
</layout>
-2. Tab类-
<?php
class NAMESPACE_MODULENAME_Block_Adminhtml_Catalog_Product_Edit_Tab extends Mage_Adminhtml_Block_Widget
implements Mage_Adminhtml_Block_Widget_Tab_Interface
{
public function canShowTab()
{
return true;
}
public function getTabLabel()
{
return $this->__('Custom Tab');
}
public function getTabTitle()
{
return $this->__('Custom Tab');
}
public function isHidden()
{
return false;
}
public function getTabUrl()
{
return $this->getUrl('*/*/customtab', array('_current' => true));
}
public function getTabClass()
{
return 'ajax';
}
}
注意:
关于后端开发的文档很少,我感觉像是Magento Devs。不好意思分享有关该领域的知识(这就是上述问题的原因。)
资料来源:
该技术可以在这里找到:
- http://www.webspeaks.in/2012/02/create-custom-tab-in-magento-product-addedit-page.html
,并且在这种Inchoo文章的评论:
- http://inchoo.net/ecommerce/magento/how-to-add-custom-product-relations-in-magento/
这是我的方法。
创建事件的观察者core_block_abstract_prepare_layout_after
。不确定这是否是最好的活动。
<adminhtml>
...
<events>
<core_block_abstract_prepare_layout_after>
<observers>
<[namespace]_[module]_product>
<type>singleton</type>
<class>[module]/adminhtml_observer</class>
<method>addProductTabBlock</method>
</[namespace]_[module]_product>
</observers>
</core_block_abstract_prepare_layout_after>
</events>
....
</adminhtml>
然后创建观察者
class [Namespace]_[Module]_Model_Adminhtml_Observer {
//this checks if the tab can be added. You don't want to add the tab when selecting the product type and attribute set or when selecting the configurable attributes.
protected function _canAddTab($product){
if ($product->getId()){
return true;
}
if (!$product->getAttributeSetId()){
return false;
}
$request = Mage::app()->getRequest();
if ($request->getParam('type') == 'configurable'){
if ($request->getParam('attributes')){
return true;
}
}
return false;
}
//the method that actually adds the tab
public function addProductTabBlock($observer){
$block = $observer->getEvent()->getBlock();
$product = Mage::registry('product');
//if on product tabs block and the tab can be added...
if ($block instanceof Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs && $this->_canAddTab($product)){
//in case there is an ajax tab
$block->addTab('some_identifier_here', array(
'label' => Mage::helper('catalog')->__('Some Label here'),
'url' => Mage::helper('adminhtml')->getUrl('adminhtml/some_url/here', array('_current' => true)),
'class' => 'ajax',
));
//in case it's a simple content tab
$block->addTab('other_identifier_here', array(
'label' => Mage::helper('catalog')->__('Label here'),
'content' => $this->getLayout()->createBlock('[module]/block_alias')->toHtml(),
));
}
return $this;
}
}
只需确保替换[namespace]
并[module]
使用模块所具有的值即可。
将以下代码添加到您的config.xml
文件中
<blocks>
...
<modulename>
<class>Company_ModuleName_Block</class>
</modulename>
<adminhtml>
<rewrite>
<catalog_product_edit_tabs>Company_ModuleName_Block_Adminhtml_Tabs</catalog_product_edit_tabs>
</rewrite>
</adminhtml>
...
</blocks>
之后,您应该创建一个新文件: Company/ModuleName/Block/Adminhtml/Tabs.php
<?php
class Company_ModuleName_Block_Adminhtml_Tabs extends Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs
{
private $parent;
protected function _prepareLayout()
{
//get all existing tabs
$this->parent = parent::_prepareLayout();
//add new tab
$this->addTab('tabid', array(
'label' => Mage::helper('catalog')->__('New Tab'),
'content' => $this->getLayout()
->createBlock('modulename/adminhtml_tabs_tabid')->toHtml(),
));
return $this->parent;
}
}
接下来,创建一个文件: Company/ModuleName/Block/Adminhtml/Tabs/Tabid.php
<?php
class Company_ModuleName_Block_Adminhtml_Tabs_Tabid extends Mage_Adminhtml_Block_Widget
{
public function __construct()
{
parent::__construct();
$this->setTemplate('modulename/newtab.phtml');
}
}
app / code / local / Mage / Adminhtml / Block / Catalog / Product / Edit / Tabs.php
),并将以下代码段添加到函数中 _prepareLayout()
$this->addTab('tabid', array(
'label' => Mage::helper('catalog')->__('New Tab'),
'content' => $this->_translateHtml($this->getLayout()
->createBlock('modulname/adminhtml_tabs_tabid')->toHtml()),
));
您始终可以创建任何核心文件的本地文件。