我需要重写块 catalog_product_edit_tab_options_type_select 来自定义。我正在使用 Magento 1.7.0.2。提前致谢。
我在我的模块 etc/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;
}
}
自定义选择块类,
class My_Module_Block_Adminhtml_Catalog_Product_Edit_Tab_Options_Type_Select extends
Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Options_Type_Select
{
/**
* Class constructor
*/
public function __construct()
{
parent::__construct();
$this->setTemplate('my/module/catalog/product/edit/tab/options/type/select.phtml');
}
protected function _prepareLayout()
{
$this->setChild('dimension_fetchbutton',
$this->getLayout()->createBlock('adminhtml/widget_button')
->setData(array(
'label' => Mage::helper('catalog')->__('Get Dimensions'),
'class' => 'add-dimensions dimension_button_{{option_id}}',
'id' => '{{option_id}}',
'style' => 'display:none;float:left;'
))
);
return parent::_prepareLayout();
}
public function getCustomButtonHTML()
{
return $this->getChildHtml('dimension_fetchbutton');
}
}
抛出的错误:致命错误:在 /home/vhosts/Magento/Project/app/code/community/My/Module/Block/Adminhtml/Catalog/Product/Edit/Tab 中的非对象上调用成员函数 setCanReadPrice() /Options/Option.php 在第 81 行
在选项块类上标记为**的错误行。需要一个解决方案来克服这个致命错误。