Magento Forum

   
Overriding Core Models with a Custom Module --- Need some basic help
 
aaronshaf
Jr. Member
 
Total Posts:  22
Joined:  2009-02-17
 

Hi Magento gurus, I have a question. I am getting started with module development and would like to override a core model’s method. I followed the steps given here:

http://www.belanur.de/blog/2008/09/05/overriding-core-models-with-a-custom-module/

I followed them to a T, but it’s not working, meaning that a product’s price is not being changed in the store.

To make sure Price.php was even being loaded, I put a die(’test’); statement at the top of the file, but alas, it wasn’t being loaded. In the main index.php file I uncommented these two lines:

Mage::setIsDeveloperMode(true);

ini_set('display_errors'1);

But no errors are showing. The price difference doesn’t take effect, and the Price.php file isn’t even loaded.

To sum up, I have this at app/code/local/MyCompany/ConstPrice/etc/config.xml:

<?xml version="1.0" encoding="utf-8"?>
<config>
  <
modules>
    <
MyCompany_ConstPrice>
      <
version>0.1.0</version>
    </
MyCompany_ConstPrice>
  </
modules>
  <global>
    <
models>
      <
catalog>
        <
rewrite>
          <
product_type_price>MyCompany_ConstPrice_Model_Price</product_type_price>
        </
rewrite>
      </
catalog>
    </
models>
  </global>
</
config>

And this at app/code/local/MyCompany/ConstPrice/Model/Price.php:

<?php
  
class MyCompany_ConstPrice_Model_Price extends Mage_Catalog_Model_Product_Type_Price
  {
    
public function getPrice($product)
    
{
      
return 50.00;
    
}
  }

And this at app/etc/modules/MyCompany_All.xml:

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

Your help is appreciated. Any ideas? How can I further troubleshoot my xml module files to see if they’re working, to see if they’re loading correctly?

Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Thet
Jr. Member
 
Total Posts:  4
Joined:  2008-10-15
 

I’m not sure if you will need

<depends>
    <
Mage_Catalog />
</
depends>

 
Magento Community Magento Community
Magento Community
Magento Community
 
aaronshaf
Jr. Member
 
Total Posts:  22
Joined:  2009-02-17
 

Thanks for the suggestion. I tried

<?xml version="1.0"?>
<config>
  <
modules>
    <
MyCompany_ConstPrice>
      <
active>true</active>
      <
codePool>local</codePool>
      <
depends>
        <
Mage_Catalog />
      </
depends
    </
MyCompany_ConstPrice>
  </
modules>
</
config>

But it still doesn’t work :-\

 
Magento Community Magento Community
Magento Community
Magento Community
 
aaronshaf
Jr. Member
 
Total Posts:  22
Joined:  2009-02-17
 

I’m an idiot… it was a caching issue!

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