我試圖在類別編輯頁面的頂部添加一個額外的選項卡。默認的是:常規信息,顯示設置,自定義設計和類別產品。將額外的選項卡添加到Magento中的類別編輯頁面
所以,我創建了一個新的模塊,重寫生成選項卡的塊。下面是從config.xml中相關片段:
<blocks>
<adminhtml>
<rewrite>
<catalog_category_tabs>
MyNamespace_MyModule_Block_Catalog_Category_Tabs
</catalog_category_tabs>
</rewrite>
</adminhtml>
</blocks>
這裏是我的塊覆蓋默認的Magento一個:
class MyNamespace_MyModule_Block_Catalog_Category_Tabs extends Mage_Adminhtml_Block_Catalog_Category_Tabs
{
protected function _prepareLayout()
{
$categoryAttributes = $this->getCategory()->getAttributes();
if (!$this->getCategory()->getId()) {
foreach ($categoryAttributes as $attribute) {
$default = $attribute->getDefaultValue();
if ($default != '') {
$this->getCategory()->setData($attribute->getAttributeCode(), $default);
}
}
}
$attributeSetId = $this->getCategory()->getDefaultAttributeSetId();
/** @var $groupCollection Mage_Eav_Model_Resource_Entity_Attribute_Group_Collection */
$groupCollection = Mage::getResourceModel('eav/entity_attribute_group_collection')
->setAttributeSetFilter($attributeSetId)
->setSortOrder()
->load();
$defaultGroupId = 0;
foreach ($groupCollection as $group) {
/* @var $group Mage_Eav_Model_Entity_Attribute_Group */
if ($defaultGroupId == 0 or $group->getIsDefault()) {
$defaultGroupId = $group->getId();
}
}
foreach ($groupCollection as $group) {
/* @var $group Mage_Eav_Model_Entity_Attribute_Group */
$attributes = array();
foreach ($categoryAttributes as $attribute) {
/* @var $attribute Mage_Eav_Model_Entity_Attribute */
if ($attribute->isInGroup($attributeSetId, $group->getId())) {
$attributes[] = $attribute;
}
}
// do not add grops without attributes
if (!$attributes) {
continue;
}
$active = $defaultGroupId == $group->getId();
$block = $this->getLayout()->createBlock($this->getAttributeTabBlock(), '')
->setGroup($group)
->setAttributes($attributes)
->setAddHiddenFields($active)
->toHtml();
$this->addTab('group_' . $group->getId(), array(
'label' => Mage::helper('catalog')->__($group->getAttributeGroupName()),
'content' => $block,
'active' => $active
));
}
$this->addTab('products', array(
'label' => Mage::helper('catalog')->__('Category Products'),
'content' => $this->getLayout()->createBlock(
'adminhtml/catalog_category_tab_product',
'category.product.grid'
)->toHtml(),
));
// dispatch event add custom tabs
Mage::dispatchEvent('adminhtml_catalog_category_tabs', array(
'tabs' => $this
));
$this->addTab('myextratab', array(
'label' => Mage::helper('catalog')->__('My Extra Tab'),
'content' => 'Here is the contents for my extra tab'
));
return parent::_prepareLayout();
}
}
注意額外的標籤代碼:
$this->addTab('myextratab', array(
'label' => Mage::helper('catalog')->__('My Extra Tab'),
'content' => 'Here is the contents for my extra tab'
));
但是,屏幕的右側只是空白。類別樹仍然存在,但點擊一個類別中的螢火蟲給這個JavaScript錯誤:ReferenceError: category_info_tabsJsTabs is not defined
UPDATE: 已經上閱讀this duplicate question and aswer所以它看起來像我所做的一切。有一些佈局代碼我錯過了嗎?
任何幫助是大規模讚賞。