Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

How to override method from Catalog/Model/Product/Type/Price.php ? 
 
ftissot
Jr. Member
 
Total Posts:  5
Joined:  2008-07-25
 

Hello,

I’m trying to override public method ”getPrice” from Mage/Catalog/Model/Product/Type/Price.php but with no results. My file containing the new class doesn’t run…

I’ve create a file /app/etc/modules/Mycompany_All.xml with :

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

I’ve create a file /app/code/local/Mycompany/Catalog/etc/config.xml

<?xml version="1.0"?>
<config>
  <global>
    <
models>
        <
catalog>
          <
rewrite>
              <
Product_Type_Price>
                <class>
Mycompany_Catalog_Model_Product_Type_Price</class>
              </
Product_Type_Price>
          </
rewrite>
        </
catalog>
    </
models>
  </global>
</
config>

And then the file /app/local/Mycompany/Catalog/Model/Product/Type/Price.php

<?php

// a die() to be sure that the file is execute
die();

require_once 
'Mage/Catalog/Model/Product/Type/Price.php';
class 
Mycompany_Catalog_Model_Product_Type_Price extends Mage_Catalog_Model_Product_Type_Price
{

    
public function getPrice($product)
    
{
        
// I want my product to have the same fixed price : 100 dollars
        
return 100;
    
}
}

Could anyone help me to make this file running ?

Thanx a lot.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Belanur
Jr. Member
 
Total Posts:  11
Joined:  2008-06-25
Hannover, Germany
 

Hi,

here is a working example:

file /app/etc/Modules/SHeuer_Price.xml

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

file /app/code/local/SHeuer/Price/etc/config.xml

<?xml version="1.0" encoding="utf-8"?>
<config>
  <
modules>
    <
SHeuer_Price>
      <
version>0.1.0</version>
    </
SHeuer_Price>
  </
modules>
  <global>
    <
models>
      <
catalog>
        <
rewrite>
          <
product_type_price>SHeuer_Price_Model_Price</product_type_price>
        </
rewrite>
      </
catalog>
    </
models>
  </global>
  <
frontend>
    <
routers />
    <
events />
    <
translate />
    <
layout />
  </
frontend>
  <default>
    <
config_vars />
  </default>
</
config>

file /app/code/local/SHeuer/Price/Model/Price.php

<?php

  
class SHeuer_Price_Model_Price extends Mage_Catalog_Model_Product_Type_Price
  {
    
public function getPrice($product)
    
{
      
die('function called');
    
}
  }

?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
peng783
Jr. Member
 
Total Posts:  4
Joined:  2013-01-18
 

This blog post explains how to extend a model class and overrides its fuctions.
The example provided is to extending the User model in Admin module.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top