0

我需要重写块 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 行

在选项块类上标记为**的错误行。需要一个解决方案来克服这个致命错误。

4

1 回答 1

0

要使其工作,您应该覆盖
/app/design/adminhtml/default/default/template/catalog/product/edit/options/option.phtml
模板文件并将您的案例添加到 switch 块中,如下所示:

....
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;
}...
于 2013-06-26T15:02:41.660 回答