how can i override Mage_Catalog_Model_Resource_Product_Option_Value?
my config.xml:
<config>
<modules>
<My_Module>
<version>0.0.1</version>
</My_Module>
</modules>
<global>
<models>
<catalog_resource>
<rewrite>
<product_option_type_price>
My_Module_Catalog_Model_Resource_Product_Option_Value
</product_option_type_price>
</rewrite>
</catalog_resource>
</models>
</global>
and my class
class My_Module_Catalog_Model_Resource_Product_Option_Value
extends Mage_Catalog_Model_Resource_Product_Option_Value
{ }
Yeach sure You can, but config.xml should look like:
<catalog_resource>
<rewrite>
<product_option_value>My_Module_Catalog_Model_Resource_Product_Option_Value</product_option_value>
</rewrite>
</catalog_resource>
Pay attention on text wrap in 3rd line, everything must be in one line
Related
I've created a custom model to override core's Product Model.
// app/code/local/Commerce121/Catalog/Model/Product.php
include('Mage/Catalog/Model/Product.php');
class Commerce121_Catalog_Model_Product extends Mage_Catalog_Model_Product
{
public function getCompatibilityGrid()
{
return '<table width="100%"><tr><th>Year</th><th>Model</th><tr>Engine</tr></tr></table>';
}
}
// app/code/local/Commerce121/Catalog/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Commerce121_catalog>
<version>1.0</version>
</Commerce121_catalog>
</modules>
<global>
<models>
<catalog>
<rewrite>
<product>Commerce121_Catalog_Model_Product</product>
</rewrite>
</catalog>
</models>
</global>
</config>
// app/etc/modules/Commerce121_Catalog.xml
<?xml version="1.0"?>
<config>
<modules>
<Commerce121_catalog>
<active>true</active>
<codepool>local</codepool>
</Commerce121_catalog>
</modules>
</config>
In the admin the module is listed as enabled.
In app/design/frontend/.../default/template/catalog/product/view/view.phtml
I added:
echo $_product->getCompatibilityGrid();
But nothing shows (this is the view, since echo 'bla' shows). Is $_product a reference to a controller? If so, should I need to extend the controller as well?
Turs out Product model wasn't overriden. There was a part missing in the config.xml which declares the module:
<commerce121_catalog>
<class>Commerce121_Catalog_Model</class>
</commerce121_catalog>
Should be like this:
<?xml version="1.0"?>
<config>
<modules>
<Commerce121_Catalog>
<version>0.1.0</version>
</Commerce121_Catalog>
</modules>
<global>
<models>
<commerce121_catalog>
<class>Commerce121_Catalog_Model</class>
</commerce121_catalog>
<catalog>
<rewrite>
<product>Commerce121_Catalog_Model_Product</product>
</rewrite>
</catalog>
</models>
</global>
</config>
I'm new at Magento and stuggling with an issue that seems to me like it should be simple.
I want to override the Mage_Catalog_Block_Navigation class and I've created: app\code\local\Feno\Catalog\Block\Navigation.php that contains (snippet):
class Feno_Catalog_Block_Navigation extends Mage_Catalog_Block_Navigation
{
public function renderCategoriesMenuHtml($level = 0, $outermostItemClass = '', $childrenWrapClass = '', $exclude_ids = array())
{
In app\code\local\Feno\Catalog\etc\config.xml I have:
<?xml version="1.0"?>
<config>
<modules>
<Feno_Catalog>
<version>1.0.1</version>
</Feno_Catalog>
</modules>
<global>
<blocks>
<catalog>
<rewrite>
<navigation>Feno_Catalog_Block_Navigation</navigation>
</rewrite>
</catalog>
</blocks>
</global>
</config>
However when I run the page, I get this error:
Invalid method Mage_Catalog_Block_Navigation::renderCategoriesMenuHtml(Array ...
So it isn't even picking up my class..
I tried adding app\etc\modules\Feno_Catalog.xml with:
<?xml version="1.0"?>
<config>
<modules>
<Feno_Catalog>
<active>true</active>
<codePool>local</codePool>
</Feno_Catalog>
</modules>
</config>
But that doesn't work. Am I forgetting something?
As I said I'm new to Magento, so not sure where to look and Google and stackoverflow havent been able to help. FYI, I use PHPStorm so XML, etc are all valid (IDE checks)
You didn't add your new class name in your config.xml file, it should be,
<?xml version="1.0"?>
<config>
<modules>
<Feno_Catalog>
<version>0.0.0</version>
</Feno_Catalog>
</modules>
<global>
<helpers>
<catalog>
<class>Feno_Catalog_Helper</class>
</catalog>
</helpers>
<blocks>
<catalog>
<class>Feno_Catalog_Block</class>
</catalog>
<catalog>
<rewrite>
<navigation>Feno_Catalog_Block_Catalog_Navigation</navigation>
</rewrite>
</catalog>
</blocks>
</global>
</config>
And you class in app/code/local/Feno/Catalog/Blcok/Catalog/Navigation.php
<?php
class Feno_Catalog_Block_Catalog_Navigation extends Mage_Catalog_Block_Navigation
{
}
And your helper file(it is optional)
app/code/local/Feno/Catalog/Helper/Data.php
<?php
class Feno_Catalog_Helper_Data extends Mage_Core_Helper_Abstract
{
}
Update:
I forgot something to add. The module name you using Catalog is already used by magento core. So you need to change the module name or use <depends> ..</depends> tag. Otherwise module conflict may be happen or your module doesn't load. To use depends,
<Mage_Catalog>
<depends>
<Packagename_Modulename />
</depends>
</Mage_Catalog>
So your Feno_Catalog.xml (app/etc/modules) file should be,
<?xml version="1.0"?>
<config>
<modules>
<Feno_Catalog>
<active>true</active>
<codePool>local</codePool>
<version>0.0.0</version>
<depends>
<Mage_Catalog />
</depends>
</Feno_Catalog>
</modules>
</config>
I'm going to answer my own question here. I put it on hold after I didn't manage previous time and tried again today (cost me a couple of hours) and found it after searching and trying all sort of stuff.
The main issue appeared to be was that the block had to be registered in /app/etc/local.xml
...
<config>
<global>
<blocks>
<catalog>
<rewrite>
<navigation>Feno_Catalog_Block_Navigation</navigation>
</rewrite>
</catalog>
</blocks>
<install>
...
After adding this it works perfect!
Found this short and sweet blog post: http://priyasmagento.blogspot.com/2010/07/override-navigation-block.html
Decided to add the blog post content also, the site doesn't seem very well maintained and would be a shame to lose the data.
© http://priyasmagento.blogspot.com/
Create mymodulepack folder in local folder.
Path: C:\wamp\www\triangeli\app\code\local\mymodulepack
Create catalog folder inside mymodulpack namespace.
Create block, etc, helper folder inside Catalog folder.
Create Navigation.php file in block folder. Override class and write functions inside this file.
<?php
class mymodulepack_Catalog_Block_Navigation extends Mage_Catalog_Block_Navigation
{
//write the function here,which add new functionality or override the original code
public function override()
{
//write the code here
}
}
Create config.xml file inside etc folder.
<?xml version="1.0" encoding="iso-8859-1"?>
<config>
<modules>
<mymodulepack_Catalog>
<version>0.1.0</version>
</mymodulepack_Catalog>
</modules>
<global>
<blocks>
<catalog>
<rewrite>
<class>mymodulepack_Catalog_Block</class>
</rewrite>
</catalog>
</blocks>
<helpers>
<catalog>
<rewrite>
<class>mymodulepack_Catalog_Helper</class>
</rewrite>
</catalog>
</helpers>
</global>
</config>
Create Data.php file inside Helper folder.
<?php
class mymodulepack_Catalog_Helper_Data extends Mage_Core_Helper_Abstract
{ }
?>
To “activate” my new module “mymodulepack”:
In the file app\etc\local.xml reference mymodulepack under the global scope:
<config>
<global>
<blocks>
<catalog>
<rewrite>
<navigation>mymodulepack_Catalog_Block_Navigation</navigation>
</rewrite>
</catalog>
</blocks>
<install>
<date><![CDATA[Thu, 17 Dec 2009 11:50:52 +0000]]></date>
</install>
<crypt>
<key><![CDATA[d89edae607842ce91b0e36456faed63e]]></key>
</crypt>
<disable_local_modules>false</disable_local_modules>
<resources>
<db>
<table_prefix><![CDATA[]]></table_prefix>
</db>
<default_setup>
<connection>
<host><![CDATA[localhost]]></host>
<username><![CDATA[root]]></username>
<password><![CDATA[]]></password>
<dbname><![CDATA[pizzaman]]></dbname>
<active>1</active>
</connection>
</default_setup>
</resources>
<session_save><![CDATA[files]]></session_save>
</global>
<admin>
<routers>
<adminhtml>
<args>
<frontName><![CDATA[admin]]></frontName>
</args>
</adminhtml>
</routers>
</admin>
</config>
Disable cache from admin section.
I try to override Mage_Customer_AddressController, but my way doesn't work.
Used original documentation from magentocommerce.com and some blog posts (by Inchoo and Pfay) too.
Please explain me, what I'm doing wrong?
module config.xml:
<config>
<modules>
<companyname_General>
<version>1.0.5</version>
</Companyname_General>
</modules>
<global>
<helpers>
<Companyname_general>
<class>Companyname_General_Helper</class>
</Companyname_general>
</helpers>
<blocks>
<catalog>
<rewrite>
<product_list_toolbar>Companyname_General_Block_Catalog_Product_List_Toolbar</product_list_toolbar>
</rewrite>
</catalog>
</blocks>
<rewrite>
<companyname_general_customer_address>
<from><![CDATA[#^/customer/address/#]]></from>
<to>/general/customer_address</to>
</companyname_general_customer_address>
</rewrite>
</global>
<frontend>
<routers>
<customer>
<use>standard</use>
<agrs><companyname_general before="Mage_Customer">Companyname_General</companyname_general></agrs>
</customer>
</routers>
</frontend>
</config>
Companyname_General_AddressController:
<?php
require_once(Mage::getModuleDir('controllers','Mage_Customer').DS.'AddressController.php');
class Companyname_General_Customer_AddressController extends Mage_Customer_AddressController
{
public function testAction()
{
die('works too!');
}
}
ps: Magento Enterprise 1.12
First of all issue in helper Companyname_general should be companyname_general
then helper Mage::helper('companyname_general')
<helpers>
<companyname_general>
<class>Companyname_General_Helper</class>
</companyname_general>
</helpers>
config.xml(Path Is app/code/local/Companyname/General/etc/) code is
<?xml version="1.0" ?>
<config>
<modules>
<Companyname_General>
<version>1.0.5</version>
</Companyname_General>
</modules>
<global>
<helpers>
<general>
<class>Companyname_General_Helper</class>
</general>
</helpers>
<blocks>
<catalog>
<rewrite>
<product_list_toolbar>Companyname_General_Block_Catalog_Product_List_Toolbar</product_list_toolbar>
</rewrite>
</catalog>
</blocks>
</global>
<frontend>
<routers>
<customer>
<args>
<modules>
<general before="Mage_Customer">Companyname_General</general>
</modules>
</args>
</customer>
</routers>
</frontend>
</config>
controllers AddressController.php(Path: app/code/local/Companyname/General/controllers )
code is
<?php
require_once(Mage::getModuleDir('controllers','Mage_Customer').DS.'AddressController.php');
class Companyname_General_AddressController extends Mage_Customer_AddressController
{
/**
* Retrieve customer session object
*
* #return Mage_Customer_Model_Session
*/
protected function _getSession()
{
return Mage::getSingleton('customer/session');
}
public function preDispatch()
{
parent::preDispatch();
if (!Mage::getSingleton('customer/session')->authenticate($this)) {
$this->setFlag('', 'no-dispatch', true);
}
}
public function testAction()
{
die('works too!');
}
}
Module file is Companyname_General.xml path is app/etc/modules/
code are
<?xml version="1.0" ?>
<config>
<modules>
<Companyname_General>
<active>true</active>
<codePool>local</codePool>
</Companyname_General>
</modules>
</config>
I'm trying to override the _getHtml function in Mage_Page_Block_Html_Topmenu magento class
I've created a new module in app/cod/local/MyModulo/Opage
My congig.xml is:
<config>
<modules>
<MyModulo_Opage>
<version>1.0.0</version>
</MyModulo_Opage>
</modules>
<global>
<blocks>
<page>
<rewrite>
<html_topmenu>MyModulo_Opage_Block_Html_Topmenu</html_topmenu>
</rewrite>
</page>
</blocks>
</global>
My class is:
But when I test it, the category top menu doesn't appear. What I'm doing wrong?
Try below
<?xml version="1.0"?>
<config>
<modules>
<MyModulo_Opage>
<version>1.0.0</version>
</MyModulo_Opage>
</modules>
<global>
<blocks>
<page>
<rewrite>
<html_topmenu>MyModulo_Opage_Block_Page_Html_Topmenu</html_topmenu>
</rewrite>
</page>
</blocks>
</global>
</config>
Call rewrite block class path app>code>local>MyModulo>Opage>Block>Page>Html>Topmenu.php
<?php
class MyModulo_Opage_Block_Page_Html_Topmenu extends Mage_Page_Block_Html_Topmenu
{
}
Im trying to rewrite the Mage_Review_Model_Resource_Review_Summary_Collection.
The Module is activated.
The folde structure is the same as in core review.
The problem should be in the xml.
My xml is:
<?xml version="1.0"?>
<config>
<modules>
<LM_Review>
<version>0.1.0</version>
</LM_Review>
</modules>
<frontend>
<routers>
<review>
<args>
<modules>
<lm_review before="Mage_Review">LM_Review</lm_review>
</modules>
</args>
</review>
</routers>
<layout>
<updates>
<lm_review>
<file>lm/review.xml</file>
</lm_review>
</updates>
</layout>
<translate>
<modules>
<LM_Review>
<files>
<default>LM_Review.csv</default>
</files>
</LM_Review>
</modules>
</translate>
</frontend>
<global>
<models>
<review_resource>
<rewrite>
<review_summary_collection>LM_Review_Model_Resource_Review_Summary_Collection</review_summary_collection>
</rewrite>
</review_resource>
</models>
</global>
</config>
LM_All.xml in etc/modules
<LM_Review>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Review />
</depends>
</LM_Review>
The Collection.php in app/code/local/LM/Review/Model/Resource/Review/Summary/Collection.php
class LM_Review_Model_Resource_Review_Summary_Collection extends Mage_Review_Model_Resource_Review_Summary_Collection {
public function addStoreFilter($storeId) {
die('test');
}
}
Your XML is correct. With the above XML in place, if you make the factory method call
Mage::getResourceModel('review/review_summary_collection')
Magento will attempt to instantiate a
LM_Review_Model_Resource_Review_Summary_Collection
That means
Magento can't see your module (no app/etc/module file, or file is inactive, or file is pointing to the wrong code pool)
You do not have a file at LM/Review/Model/Resource/Review/Summary/Collection.php in your code pool
The class defined in Collection.php is not LM_Review_Model_Resource_Review_Summary_Collection
The class defined in Collection.php does not extend Mage_Review_Model_Resource_Review_Summary_Collection
Check the spelling and upper/lower case of your class and path names. This matters to Magento.
I found the problem. Its required to add the resource-model to the xml and not only rewrite it.
<global>
<models>
<review>
<resourceModel>review_resource</resourceModel>
</review>
<review_resource>
<rewrite>
<review_summary_collection>LM_Review_Model_Resource_Review_Summary_Collection</review_summary_collection>
</rewrite>
</review_resource>
</models>
</global>