overriding price model in magento

overriding price model in magento

September 5, 2026 · Illustrated author avatarBy Stefan Bogdanescu
overriding price model in magento

Overriding the Magento Product Price Model: A Comprehensive Guide

You’re on the right track when it comes to overriding the Magento product price model. In this post, I’ll guide you through the process step-by-step, ensuring that your app/etc/config.xml and custom price model logic are properly configured.

The Current Setup

Let’s first examine the setup provided:

  1. app/etc/config.xml: This is the main configuration file for all Magento modules. It currently contains a single active module named softweb_catalog.
<config>
  <modules>
    <softweb_catalog>
        <active>true</active>
        <codepool>local</codepool>
    </softweb_catalog>
  </modules>
</config>
  1. app/code/local/Softweb/Catalog/etc/config.xml: This is the custom configuration file for your softweb_catalog module.
<config>
<modules>
    <softweb_catalog>
        <version>0.1</version>
    </softweb_catalog>
</modules>
<global>
    <models>
        <catalog>
            <class>Softweb_Catalog_Model</class>
        </catalog>
        <catalog>
            <rewrite>
                <product_type_price>Softweb_Catalog_Model_Product_Type_Price</product_type_price>
            </rewrite>
        </catalog>
    </models>
</global>
</config>
  1. app/code/local/Softweb/Catalog/Model/Product/Type/Price.php: This is your custom price model file where you’ve overridden the getPrice method.
class Softweb_Catalog_Model_Product_Type_Price extends Mage_Catalog_Model_Product_Type_Price
{
   public function getPrice($product)
   {
      die('function called');
   }
}

The Missing Piece

The issue lies in the way you’ve structured your config.xml files. In Magento, modules are organized into different code pools—local, community, and core. Your local pool module (softweb_catalog) is currently configured correctly.

However, when you define the rewrite for the price model in your custom config file, you need to specify the correct path relative to the base directory of your Magento installation, not just within your module’s structure.

The Correct Configuration

Let me provide an example of how your config.xml files should look:

app/etc/config.xml

<config>
  <modules>
    <Softweb_Catalog>
        <active>true</active>
        <codepool>local</codepool>
    </Softweb_Catalog>
  </modules>
</config>

app/code/local/Softweb/Catalog/etc/config.xml

<config>
<modules>
    <Softweb_Catalog>
        <version>0.1</version>
    </Softweb_Catalog>
</modules>
<global>
    <models>
        <catalog>
            <class>Softweb_Catalog_Model</class>
        </catalog>
        <catalog>
            <rewrite>
                <product_type_price>
                    Softweb_Catalog_Model_Product_Type_Price
                </product_type_price>
            </rewrite>
        </catalog>
    </models>
</global>
</config>

Notice the capitalization of Softweb_Catalog in both files. Magento uses a case-sensitive approach for module identification.

The Complete Solution

Now, let’s update your custom price model file to include some actual logic:

app/code/local/Softweb/Catalog/Model/Product/Type/Price.php

class Softweb_Catalog_Model_Product_Type_Price extends Mage_Catalog_Model_Product_Type_Price
{
   public function getPrice($product)
   {
      // Your custom price calculation logic goes here.
      // For example, you might want to add a fixed percentage markup:
      $originalPrice = $this->getFinalPrice($product);
      $markupPercentage = 0.1; // 10% markup
      $newPrice = $originalPrice * (1 + $markupPercentage);

      return $newPrice;
   }
}

Conclusion

In conclusion, to successfully override the Magento product price model:

  • Ensure your config.xml files are properly configured with the correct module names and paths.
  • Use a case-sensitive approach when defining module names.
  • Provide actual logic in your custom model file to calculate or modify prices.

Remember, it’s crucial to clean your cache every time you make changes to Magento configuration files. You can do this manually or use the Mage::app()->getCacheInstance()->flush() command in your code.

For more advanced techniques and best practices for extending Magento functionality, I recommend checking out our comprehensive guide on Magento Development Best Practices. It provides a deep dive into various aspects of Magento extension development.

Happy coding! Let me know if you have any other questions.

Catalog Extensions Configuration Pricing

Our network