Magento – Overriding Price Model Doesn’t Work

overridesprice

I wanted to Override this
app\code\core\Mage\Catalog\Model\Product\Type\Price.php

First I created Module MyModule_Catalog.xml Under etc/modules

<config>
    <modules>
        <MyModule_Catalog>
            <active>true</active>
            <codePool>local</codePool>
        </MyModule_Catalog>
    </modules>
</config>

and under app/code/local/MyModule/Catalog/etc
my config.xml file

<config>
    <global>
        <models>
            <catalog>
                <rewrite>
                    <product_type_price>MyModule_Catalog_Model_Product_Type_Price</product_type_price>
                </rewrite>
            </catalog>
        </models>
    </global>
</config>

and under app/code/local/MyModule/Catalog/Model/Product/Type/
my Price.php File

and I've tried overriding _applyOptionsPrice() function but it didn't work

Heres my Price.php:

<?php 

class MyModule_Catalog_Model_Product_Type_Price extends Mage_Catalog_Model_Product_Type_Price
{

    protected function _applyOptionsPrice($product, $qty, $finalPrice)
    {
        Mage::log("Hello", null, 'optionsLog4.log');

        if ($optionIds = $product->getCustomOption('option_ids')) {
            $basePrice = $finalPrice;
            foreach (explode(',', $optionIds->getValue()) as $optionId) {
                if ($option = $product->getOptionById($optionId)) {
                    $confItemOption = $product->getCustomOption('option_'.$option->getId());

                    $group = $option->groupFactory($option->getType())
                        ->setOption($option)
                        ->setConfigurationItemOption($confItemOption);
                    $finalPrice += $group->getOptionPrice($confItemOption->getValue(), $basePrice);
                }
            }
        }

        return $finalPrice;
    }
}

Best Answer

Please do the following changes in your config.xml file. You have forgotten to define your module models:

<config>
    <global>
        <models>
            <mymodule_catalog>
                <class>MyModule_Catalog_Model</class>
            </mymodule_catalog>
            <catalog>
                <rewrite>
                    <product_type_price>MyModule_Catalog_Model_Product_Type_Price</product_type_price>
                </rewrite>
            </catalog>
        </models>
    </global>
</config>