php - Rewriting Magento Core Product Model using Module -
not sure doing wrong here.. trying 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 function :
$_product = mage::getsingleton('catalog/product'); echo $_product->test();
nothing returned. doesn't have access function. ideas? help.
your module should 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 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 can access test method.
Comments
Post a Comment