Antworten:
Persönlich würde ich mich für einen Layout- / Aktionsansatz entscheiden, der addTab()
den von bereitgestellten verwendetMage_Adminhtml_Block_Widget_Tabs
Hier sind also 2 Hauptaktionen beteiligt:
- 1. Layoutänderungen -
<?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-Klasse -
<?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';
}
}
Hinweis:
Es gibt nur sehr wenige Dokumentationen zur Backend-Entwicklung. Ich fühle mich wie Magento Devs. sind etwas schüchtern, um Wissen über diesen Bereich zu teilen (und deshalb der obigen Frage.)
Quelle:
Diese Technik finden Sie hier:
- http://www.webspeaks.in/2012/02/create-custom-tab-in-magento-product-addedit-page.html
und auch in den Kommentaren dieses Inchoo-Artikels :
- http://inchoo.net/ecommerce/magento/how-to-add-custom-product-relations-in-magento/
Hier ist, wie ich es mache.
Erstellen Sie einen Beobachter für das Ereignis core_block_abstract_prepare_layout_after
. Ich bin mir nicht sicher, ob es das beste Event ist.
<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>
Dann erstellen Sie den Beobachter
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;
}
}
So stellen Sie sicher , dass Sie ersetzen [namespace]
und [module]
mit den Werten , die Sie für Ihr Modul.
Fügen Sie Ihrer config.xml
Datei den folgenden Code hinzu
<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>
Danach sollten Sie eine neue Datei erstellen: 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;
}
}
Erstellen Sie als Nächstes eine Datei: 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 / Katalog / Produkt / Bearbeiten / Tabs.php
) und fügen Sie der Funktion das folgende Snippet hinzu _prepareLayout()
$this->addTab('tabid', array(
'label' => Mage::helper('catalog')->__('New Tab'),
'content' => $this->_translateHtml($this->getLayout()
->createBlock('modulname/adminhtml_tabs_tabid')->toHtml()),
));
Sie können jederzeit eine lokale Kerndatei erstellen.