2014-01-16 2 views
0

카테고리 편집 페이지 상단에 추가 탭을 추가하려고합니다. 기본 정보는 일반 정보, 디스플레이 설정, 사용자 정의 디자인 및 카테고리 제품입니다.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' 
     )); 

기본 젠토 하나를 덮어 여기

<blocks> 

     <adminhtml> 

      <rewrite> 

       <catalog_category_tabs> 

        MyNamespace_MyModule_Block_Catalog_Category_Tabs 

       </catalog_category_tabs> 

      </rewrite> 

     </adminhtml> 

    </blocks> 

내 블록 : 여기 config.xml에에서 관련 조각입니다 그러나 화면의 오른쪽이 비어 있습니다. 카테고리 트리가 여전히 남아 있지만, 카테고리를 클릭하면 방화범이 자바 스크립트 오류를 ​​제공합니다 ReferenceError: category_info_tabsJsTabs is not defined

UPDATE : 는에 this duplicate question and aswer을 읽을 데 그래서 내가 모든 일을 한 것 같습니다. 내가 누락 된 레이아웃 코드가 있습니까?

모든 도움을 주실 수 있습니다.

답변

5
  1. 아직 수행하지 않은 경우 캐시 및 컴파일을 해제하십시오. 관찰자가 <models>에 정의 된 <class> 접두사를 말한다에

    내 모듈이 있으므로,

    <?xml version="1.0" encoding="UTF-8"?> 
    <config> 
        <modules> 
         <Tzunghaor_Customtab> 
          <version>0.1.0</version> 
         </Tzunghaor_Customtab> 
        </modules> 
    
        <global> 
         <models> 
          <tzunghaor_customtab> 
           <class>Tzunghaor_Customtab_Model</class> 
          </tzunghaor_customtab> 
         </models> 
    
         <events> 
          <adminhtml_catalog_category_tabs> 
           <observers> 
            <tzunghaor_customtab_observer> 
             <class>tzunghaor_customtab/observer</class> 
             <method>addCategoryTab</method> 
            </tzunghaor_customtab_observer> 
           </observers> 
          </adminhtml_catalog_category_tabs> 
         </events> 
    
        </global> 
    </config> 
    

    tzunghaor_customtab/observer을 config.xml 파일 : 나는 덜 방해 느낌 때문에

는 차라리 이벤트 옵저버를 사용 /app/code/local/Tzunghaor/Customtab/Model/Observer.php에있는 Tzunghaor_Customtab_Model_Observer을 말합니다.

<?php 
class Tzunghaor_Customtab_Model_Observer 
{ 
    /** 
    * Adds a custom tab to adminhtml category page 
    * 
    * @param Varien_Event_Observer $observer 
    */ 
    public function addCategoryTab($observer) 
    { 
     $tabs = $observer->getEvent()->getTabs(); 
     $tabs->addTab('features', array(
      'label'  => Mage::helper('catalog')->__('My Extra Tab'), 
      'content' => 'Here is the contents for my extra tab' 
     )); 
    } 
} 
관련 문제