在 Magento 中重写/扩展产品类型

Rewrite / extend product type in Magento

我想覆盖 Mage_Catalog_Model_Product_Type_Configurable 中的函数。但是我不想在更新时破坏我的代码,所以我想为它写一个小模块。

我的config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Company_SaleableIndex>
            <version>0.1.0</version>
        </Company_SaleableIndex>
    </modules>
    <global>
        <models>
            <catalog>
                <rewrite>
                    <product_type_configurable>Company_SaleableIndex_Configurable</product_type_configurable>
                </rewrite>
            </catalog>
        </models>
    </global>
</config>

我正在使用的class:

<?php

class Company_SaleableIndex_Configurable extends Mage_Catalog_Model_Product_Type_Configurable {

    public function isSalable($product = false)
    {
        die('asdf');
    }

}

模块本身似乎工作正常,因为我一激活它就在前端收到错误。重写似乎也能正常工作,因为如果我删除它,不会抛出任何错误。

Fatal error:  Call to a member function setConfig() on boolean in /var/www/sites/magento/app/code/core/Mage/Catalog/Model/Product/Type.php on line 80

我在 Apache 上使用 Magento 1.9.0.1。

我做错了什么?

试试这个:

<?xml version="1.0"?>
<config>
    <modules>
        <Company_SaleableIndex>
            <version>0.1.0</version>
        </Company_SaleableIndex>
    </modules>
    <global>
        <models>
            <company_saleableIndex>
                <class>Company_SaleableIndex_Model</class>
            </company_saleableIndex>
            <catalog>
                <rewrite>
                    <product_type_configurable>Company_SaleableIndex_Model_Configurable</product_type_configurable>
                </rewrite>
            </catalog>
        </models>
    </global>
</config>

然后,在Company/SaleableIndex/Model

中创建一个php文件名Configurable.php

希望对您有所帮助