2013-05-10 108 views
1

我正在努力解決一個問題,希望你能對此有所幫助。哪裏可以更改產品上的Magento默認選項卡?

我需要改變我的產品頁面上默認產品標籤,但我無法改變它在後端,只設置了不同的屬性。

我已經把範圍縮小到一個catalog.xml文件,但我不知道確切的代碼被控制的選項卡。

我試着改變一下代碼,但沒有效果。我的Magento的安裝也很慢,這是推動我瘋了......

任何想法?

在此先感謝...

回答

1

我建議你覆蓋本地模塊中的核心文件,而不是直接更改核心文件。 下面是一個例子如何覆蓋Mage_Adminhtml_Catalog_Product_Edit_Tabs.php
創建模塊例如MyNameSpace_ModuleName內部應用程序/代碼/本地/

要註冊模塊創建應用的/ etc /模塊/ MyNameSpace_ModuleName .XML

<?xml version="1.0"?> 
<config> 
    <modules> 
    <MyNameSpace_ModuleName> 
    <codePool>local</codePool> 
    <active>true</active> 
    </MyNameSpace_ModuleName> 
    </modules> 
</config> 

myNameSpace對象/模塊名的/ etc/config.xm升

<?xml version="1.0" encoding="utf-8"?> 
<config> 
    <modules> 
     <MyNameSpace_ModuleName> 
      <version>0.1.0</version> 
     </MyNameSpace_ModuleName> 
    </modules> 
    <global> 
     <blocks> 
      <adminhtml> 
       <rewrite> 
       <cataolg_product_edit_tabs>MyNameSpace_ModuleName_Block_Adminhtml_catalog_product_edit_tabs</cataolg_product_edit_tabs> 
       </rewrite> 
      </adminhtml> 
     </blocks> 
    </global> 
</config> 

了myNameSpace /模塊名/座/ Adminhtml /目錄/產品/編輯/ tabs.php

class MyNameSpace_ModuleName_Block_Adminhtml_Catalog_Product_Edit_Tabs extends Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs 
{ 
    protected $_attributeTabBlock = 'adminhtml/catalog_product_edit_tab_attributes'; 

    public function __construct() 
    { 
     parent::__construct(); 
     $this->setId('product_info_tabs'); 
     $this->setDestElementId('product_edit_form'); 
     $this->setTitle(Mage::helper('catalog')->__('Product Information')); 
    } 

    protected function _prepareLayout() 
    { 
     $product = $this->getProduct(); 

     if (!($setId = $product->getAttributeSetId())) { 
      $setId = $this->getRequest()->getParam('set', null); 
     } 

     if ($setId) { 
      $groupCollection = Mage::getResourceModel('eav/entity_attribute_group_collection') 
       ->setAttributeSetFilter($setId) 
       ->setSortOrder() 
       ->load(); 

      foreach ($groupCollection as $group) { 
       $attributes = $product->getAttributes($group->getId(), true); 
       // do not add groups without attributes 

       foreach ($attributes as $key => $attribute) { 
        if(!$attribute->getIsVisible()) { 
         unset($attributes[$key]); 
        } 
       } 

       if (count($attributes)==0) { 
        continue; 
       } 

       $this->addTab('group_'.$group->getId(), array(
        'label'  => Mage::helper('catalog')->__($group->getAttributeGroupName()), 
        'content' => $this->_translateHtml($this->getLayout()->createBlock($this->getAttributeTabBlock(), 
         'adminhtml.catalog.product.edit.tab.attributes')->setGroup($group) 
          ->setGroupAttributes($attributes) 
          ->toHtml()), 
       )); 
      } 

      if (Mage::helper('core')->isModuleEnabled('Mage_CatalogInventory')) { 
       $this->addTab('inventory', array(
        'label'  => Mage::helper('catalog')->__('Inventory'), 
        'content' => $this->_translateHtml($this->getLayout() 
         ->createBlock('adminhtml/catalog_product_edit_tab_inventory')->toHtml()), 
       )); 
      } 

      /** 
      * Don't display website tab for single mode 
      */ 
      if (!Mage::app()->isSingleStoreMode()) { 
       $this->addTab('websites', array(
        'label'  => Mage::helper('catalog')->__('Websites'), 
        'content' => $this->_translateHtml($this->getLayout() 
         ->createBlock('adminhtml/catalog_product_edit_tab_websites')->toHtml()), 
       )); 
      } 

      $this->addTab('categories', array(
       'label'  => Mage::helper('catalog')->__('Categories'), 
       'url'  => $this->getUrl('*/*/categories', array('_current' => true)), 
       'class'  => 'ajax', 
      )); 

      $this->addTab('related', array(
       'label'  => Mage::helper('catalog')->__('Related Products'), 
       'url'  => $this->getUrl('*/*/related', array('_current' => true)), 
       'class'  => 'ajax', 
      )); 

      $this->addTab('upsell', array(
       'label'  => Mage::helper('catalog')->__('Up-sells'), 
       'url'  => $this->getUrl('*/*/upsell', array('_current' => true)), 
       'class'  => 'ajax', 
      )); 

      $this->addTab('crosssell', array(
       'label'  => Mage::helper('catalog')->__('Cross-sells'), 
       'url'  => $this->getUrl('*/*/crosssell', array('_current' => true)), 
       'class'  => 'ajax', 
      )); 

      $storeId = 0; 
      if ($this->getRequest()->getParam('store')) { 
       $storeId = Mage::app()->getStore($this->getRequest()->getParam('store'))->getId(); 
      } 

      $alertPriceAllow = Mage::getStoreConfig('catalog/productalert/allow_price'); 
      $alertStockAllow = Mage::getStoreConfig('catalog/productalert/allow_stock'); 

      if (($alertPriceAllow || $alertStockAllow) && !$product->isGrouped()) { 
       $this->addTab('productalert', array(
        'label'  => Mage::helper('catalog')->__('Product Alerts'), 
        'content' => $this->_translateHtml($this->getLayout() 
         ->createBlock('adminhtml/catalog_product_edit_tab_alerts', 'admin.alerts.products')->toHtml()) 
       )); 
      } 

      if($this->getRequest()->getParam('id', false)) { 
       if (Mage::helper('catalog')->isModuleEnabled('Mage_Review')) { 
        if (Mage::getSingleton('admin/session')->isAllowed('admin/catalog/reviews_ratings')){ 
         $this->addTab('reviews', array(
          'label' => Mage::helper('catalog')->__('Product Reviews'), 
          'url' => $this->getUrl('*/*/reviews', array('_current' => true)), 
          'class' => 'ajax', 
         )); 
        } 
       } 
       if (Mage::helper('catalog')->isModuleEnabled('Mage_Tag')) { 
        if (Mage::getSingleton('admin/session')->isAllowed('admin/catalog/tag')){ 
         $this->addTab('tags', array(
         'label'  => Mage::helper('catalog')->__('Product Tags'), 
         'url' => $this->getUrl('*/*/tagGrid', array('_current' => true)), 
         'class' => 'ajax', 
         )); 

         $this->addTab('customers_tags', array(
          'label'  => Mage::helper('catalog')->__('Customers Tagged Product'), 
          'url' => $this->getUrl('*/*/tagCustomerGrid', array('_current' => true)), 
          'class' => 'ajax', 
         )); 
        } 
       } 

      } 

      /** 
      * Do not change this tab id 
      * @see Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs_Configurable 
      * @see Mage_Bundle_Block_Adminhtml_Catalog_Product_Edit_Tabs 
      */ 
      if (!$product->isGrouped()) { 
       $this->addTab('customer_options', array(
        'label' => Mage::helper('catalog')->__('Custom Options'), 
        'url' => $this->getUrl('*/*/options', array('_current' => true)), 
        'class' => 'ajax', 
       )); 
      } 

     } 
     else { 
      $this->addTab('set', array(
       'label'  => Mage::helper('catalog')->__('Settings'), 
       'content' => $this->_translateHtml($this->getLayout() 
        ->createBlock('adminhtml/catalog_product_edit_tab_settings')->toHtml()), 
       'active' => true 
      )); 
     } 
     return parent::_prepareLayout(); 
    } 
} 

您可以添加內部_preparelayout新的選項卡()函數。以同樣的方式,你也可以覆蓋其他文件,並可以改變任何你想改變的東西。
爲了正確反映更改,請確保清理緩存。

+0

偉大的信息。我一定會嘗試一下並儘快回覆。 – 2013-05-10 14:55:11

+0

我現在已經設置了文件夾,但是如何激活該模塊? – 2013-05-10 14:57:45

+0

@RenéHansen:要註冊你的模塊,你只需要在app/etc/modules /文件夾內創建一個xml文件MyNameSpace_ModuleName.xml。爲了您的理解,我正在更新代碼。 – 2013-05-11 18:25:45

0

你可以找到在此塊文件app \代碼\核心選項卡\法師\ Adminhtml \塊\目錄\產品\編輯\ Tabs.php

如果你是看着這個標籤,你可以找到標籤

例如相關產品,它具有這種類型的網址$this->getUrl('*/*/related', array('_current' => true)),此網址依次調用此adminhtml_catalog_product_related操作,此操作在catalog.xml中指定。

<adminhtml_catalog_product_related> 
    <block type="core/text_list" name="root" output="toHtml"> 
     <block type="adminhtml/catalog_product_edit_tab_related" name="catalog.product.edit.tab.related"/> 
     <block type="adminhtml/widget_grid_serializer" name="related_grid_serializer"> 
      <reference name="related_grid_serializer"> 
       <action method="initSerializerBlock"> 
        <grid_block_name>catalog.product.edit.tab.related</grid_block_name> 
        <data_callback>getSelectedRelatedProducts</data_callback> 
        <hidden_input_name>links[related]</hidden_input_name> 
        <reload_param_name>products_related</reload_param_name> 
       </action> 
       <action method="addColumnInputName"> 
        <input_name>position</input_name> 
       </action> 
      </reference> 
     </block> 
    </block> 
</adminhtml_catalog_product_related> 

所以你可以輕鬆找到你想要改變的東西。

+0

謝謝,我找到了該文件,我會檢查出來。 – 2013-05-10 12:27:07