2013-05-13 81 views
0

我需要重新編寫block catalog_product_edit_tab_options_type_select來定製。我正在使用Magento 1.7.0.2。提前致謝。需要重寫Adminhtml塊catalog_product_edit_tab_options_type_select

我已經在我的模塊等/ config.xml中寫如下,

<config> 
    <modules> 
     <My_Module> 
      <version>0.1.0</version> 
     </My_Module> 
    </modules> 
    <global> 
     ......... 
     <blocks> 
      <settings> 
       <class>My_Module_Block</class> 
      </settings> 
     <adminhtml> 
      <rewrite> 
      <catalog_product_edit_tab_options_type_select> 
       My_Module_Block_Adminhtml_Catalog_Product_Edit_Tab_Options_Type_Select 
      </catalog_product_edit_tab_options_type_select> 
      </rewrite> 
       <rewrite> 
     <catalog_product_edit_tab_options> 
      My_Module_Block_Adminhtml_Catalog_Product_Edit_Tab_Options 
     </catalog_product_edit_tab_options> 
     </rewrite> 
     </adminhtml> 
      ....... 
     </blocks> 
    </global> 
</config> 

重寫選項座級,

class My_Module_Block_Adminhtml_Catalog_Product_Edit_Tab_Options_Option extends Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Options_Option 
{ 
    /** 
    * Class constructor 
    */ 
    public function __construct() 
    { 
     parent::__construct(); 
     $this->setTemplate('my/module/catalog/product/edit/tab/options/option.phtml'); 
     $this->setCanReadPrice(true); 
     $this->setCanEditPrice(true); 
    } 

    protected function _prepareLayout() 
    { 
     $this->setChild('dimension_fetchbutton', 
      $this->getLayout()->createBlock('adminhtml/widget_button') 
       ->setData(array(
        'label' => Mage::helper('catalog')->__('Get Dimensions'), 
        'class' => 'add_dimensions', 
        'id' => 'add_dimensions' 
       )) 
     ); 

     /*$this->setChild('custom_select_option_type', 
       $this->getLayout()->createBlock('settings/catalog_product_edit_tab_options_type_select') 
     );*/ 

     return parent::_prepareLayout(); 
    } 

    public function getDimensionButtonHTML() 
    { 
     return $this->getChildHtml('dimension_fetchbutton'); 
    } 

    /** 
    * Retrieve html templates for different types of product custom options 
    * 
    * @return string 
    */ 
    public function getTemplatesHtml() 
    { 
     $canEditPrice = $this->getCanEditPrice(); 
     $canReadPrice = $this->getCanReadPrice(); 
     $this->getChild('select_option_type') 
      *****->setCanReadPrice($canReadPrice) 
      ->setCanEditPrice($canEditPrice);****** 

     $this->getChild('file_option_type') 
      ->setCanReadPrice($canReadPrice) 
      ->setCanEditPrice($canEditPrice); 

     $this->getChild('date_option_type') 
      ->setCanReadPrice($canReadPrice) 
      ->setCanEditPrice($canEditPrice); 

     $this->getChild('text_option_type') 
      ->setCanReadPrice($canReadPrice) 
      ->setCanEditPrice($canEditPrice); 

     $templates = $this->getChildHtml('text_option_type') . "\n" . 
      $this->getChildHtml('file_option_type') . "\n" . 
      $this->getChildHtml('select_option_type') . "\n" . 
      $this->getChildHtml('date_option_type'); 
     return $templates; 
    } 

} 

選擇自定義模塊類,

​​

錯誤拋出:致命錯誤:調用/ home/vhosts/Magento/Project/app/code/c中的非對象成員函數setCanReadPrice()在線81上的ommunity /我的/模塊/塊/管理員/目錄/產品/編輯/選項卡/選項/ Option.php

錯誤行標記爲**上的選項塊類。 需要一個解決方案來克服這個致命的錯誤。

回答

0

爲了使它工作,你應該重寫
/app/design/adminhtml/default/default/template/catalog/product/edit/options/option.phtml
模板文件,並添加你的情況給開關塊如下:

.... 
switch(element.getValue()){ 
    case 'field': 
    case 'area': 
     template = OptionTemplateText; 
     group = 'text'; 
     break; 
    case 'file': 
     template = OptionTemplateFile; 
     group = 'file'; 
     break; 
    case 'drop_down': 
    case 'radio': 
    case 'checkbox': 
    case 'multiple': 
     template = OptionTemplateSelect; 
     group = 'select'; 
     break; 
    case 'date': 
    case 'date_time': 
    case 'time': 
     template = OptionTemplateDate; 
     group = 'date'; 
     break; 
    case 'select_option_type':   /* here   */ 
     template = OptionTemplateSelect; /* your template */ 
     group = 'select';    /* your group */ 
     break; 
    default: 
     template = ''; 
     group = 'unknown'; 
     break; 
}...