2

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;
    }
}
7
  • change myModule folder name to MyModule
    – Amit Bera
    Commented Apr 13, 2015 at 7:13
  • Don't forget to flush your caches as well. Commented Apr 13, 2015 at 7:15
  • @AmitBera yes Amit its Already in that format but i replaced for just representation here Commented Apr 13, 2015 at 7:18
  • i flushed the cach nothing worked Commented Apr 13, 2015 at 7:22
  • 1
    You can override protected methods perfectly, there's no problem there. You should always stick to the original visibility though...
    – 7ochem
    Commented Apr 13, 2015 at 8:22

2 Answers 2

2

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>
3
  • IconDesign is myModule is the Module name Commented Apr 13, 2015 at 8:10
  • If IconDesign is your module name then please specify your namespace. and make the directory structure like app/code/local/namespaceName/IconDesign/ and place the Price.php file inside app/code/local/namespanceName/IconDesign/Model/Catalog/Product/Type/ Commented Apr 13, 2015 at 8:15
  • @AhmedAborady, the problem is in defining your MyModule models. I'll update this answer to use MyModule
    – 7ochem
    Commented Apr 13, 2015 at 8:16
1

You main issue Module NameSpace.

Module NameSpace is not match with stucture

As per as magento system, IconDesign_Catalog should be MyModule_Catalog. According to magento, in every helper,model and controller all php classes at custom module should be start with ModuleNameSpace_ModuleName .

This class name has been taken from Folders name. like:

IF Modules basic folder location is app/code/local/ModuleNameSapce/ModuleName.

Then the Basic Classes on all php classes is ModuleNameSapce_ModuleName In You

<?xml version="1.0" ?>
<config>
<modules>
    <MyModule_Catalog><!-- Should be   from  IconDesign_Catalog to  MyModule_Catalog -->
        <active>true</active>
        <codePool>local</codePool>
     </MyModule_Catalog>
</modules>
</config>
6
  • IconDesign is myModule is the Module name Commented Apr 13, 2015 at 8:11
  • And The Module is running already in admin system > configuration > advanced Commented Apr 13, 2015 at 8:12
  • I have updated your question to use MyModule everywhere in it's text consistently.
    – 7ochem
    Commented Apr 13, 2015 at 8:14
  • thats what already done Commented Apr 13, 2015 at 8:19
  • @AmitBera, the OP has tried to replace the original IconDesign_Catalog module name/name space with a dummy one MyModule_Catalog when placing his question here on Magento SE. He didn't do this on all places, so that's what has caused the confusion here... ;)
    – 7ochem
    Commented Apr 13, 2015 at 8:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.