0

我正在尝试覆盖 getSelectionQtyTitlePrice 方法我创建了一个文件 My_Bundle.xml

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

在 PA -> System->Advanced 模块存在并在 app/code/local/My/Bundle/Block/Catalog/Product/View/Type/Bundle Option.php 中启用

class My_Bundle_Block_Catalog_Product_View_Type_Bundle_Option extends Mage_Bundle_Block_Catalog_Product_View_Type_Bundle_Option
{
  public function getSelectionQtyTitlePrice($_selection, $includeContainer = false)
    {
        $price = $this->getProduct()->getPriceModel()->getSelectionPreFinalPrice($this->getProduct(), $_selection);
        $this->setFormatProduct($_selection);
        $priceTitle = $_selection->getSelectionQty()*1 . ' x ' . $this->escapeHtml($_selection->getName());

        $priceTitle .= ' &nbsp; ' . ($includeContainer ? '<span class="price-notice">' : '')
            . '' . $this->formatPriceString($price, $includeContainer)
            . ($includeContainer ? '</span>' : '');

        return  $priceTitle;
    }
}

在 app/code/local/My/Bundle/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <My_Bundle>
            <version>0.0.1</version>
        </My_Bundle>
    </modules>

    <global>
        <blocks>
            <bundle>
                   <rewrite>
                       <catalog_product_view_type_bundle_option>My_Bundle_Block_Catalog_Product_View_Type_Bundle_Option</catalog_product_view_type_bundle_option>
                    </rewrite>
            </bundle>
        </blocks>
     </global>
</config>

但此解决方案不会覆盖 getSelectionQtyTitlePrice 方法。谢谢帮助

4

1 回答 1

2

看看@http ://www.magentocommerce.com/boards/viewthread/265060/#t357807

由于这个块永远不会被实例化,你应该覆盖它的子类并在它们中应用你的本地更改。

所以:在 config.xml

<bundle> 
    <rewrite> 
        <catalog_product_view_type_bundle_option_select>Module_Block_Bundle_Option_Select</catalog_product_view_type_bundle_option_select> 
        <catalog_product_view_type_bundle_option_multi>Module_Block_Bundle_Option_Multi</catalog_product_view_type_bundle_option_multi> 
        <catalog_product_view_type_bundle_option_radio>Module_Block_Bundle_Option_Radio</catalog_product_view_type_bundle_option_radio> 
        <catalog_product_view_type_bundle_option_checkbox>Module_Block_Bundle_Option_Checkbox</catalog_product_view_type_bundle_option_checkbox>
    </rewrite> 
</bundle>
于 2013-02-18T14:08:16.587 回答