0
votes

Not sure what I am doing wrong here.. but am trying to rewrite Magento core Catalog Product Model (app/code/Mage/Catalog/Model/Product) using custom module. See code below:

app/code/local/James/Catalog/etc/config.xml :

   <?xml version="1.0"?>
<config>
<modules>
   <James_Catalog>
        <version>1.0.1</version>
   </James_Catalog>
</modules>
<global>
  <models>
   <catalog>
     <rewrite>
       <product>James_Catalog_Model_Product</product>
     </rewrite>
    </catalog>
  </models>
</global>
</config>

app/code/local/James/Catalog/Model/Product.php :

<?php
require_once('Mage/Catalog/Model/Product.php');

class James_Catalog_Model_Product extends Mage_Catalog_Model_Product {

public function Test() {

return "Function Called";
}   
}

app/etc/modules/James_Catalog.xml :

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

Then, accessing the function :

$_product = Mage::getSingleton('catalog/product');

echo $_product->Test();

Nothing is returned. It doesn't look like I have access to the function. Ideas? Thanks for the help.

1
instead of <catalog> give some unique name for example - <james_catalog></james_catalog>.. Also check error log is there any error ?rajatsaurastri
$_product = Mage::getSingleton('catalog/product'); also this will call core model instead try with $_product = Mage::getSingleton('james_catalog/product');rajatsaurastri

1 Answers

2
votes

Your Module should be like following ...

Configuration file app/code/local/James/TestCatalog/etc/config.etc

<?xml version="1.0"?>
<config>
  <modules>
    <James_TestCatalog>
      <version>1.0.0</version>
    </James_TestCatalog>
  </modules>
  <global>
    <models>
        <catalog>
            <rewrite>
                <product>James_TestCatalog_Model_Catalog_Product</product>
            </rewrite>
        </catalog>
    </models>
  </global>
</config> 

And model file with this path : app/code/local/James/TestCatalog/Model/Catalog/Product.php

class James_TestCatalog_Model_Catalog_Product extends Mage_Catalog_Model_Product
{
     //your code here ...
     public function Test() {
         return "Function Called";
     }
}

Now you can access your test method.