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>
Related
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'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
{
}
i want to rewrite the block file : /app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Select.php, below is my steps, but it is not working :
ScreentShot: http://imm.io/J36p
Code: http://www.heypasteit.com/clip/0JJ8
who know what the problem is ?
In the linked code (below for posterity), the path global/blocks/catalog/rewrite/Product_View_Options_Select
should be
global/blocks/catalog/rewrite/product_view_options_select, because the block class is specified using lowercase in layout XML files (eg. https://github.com/benmarks/magento-mirror/blob/1.7.0.2/app/design/frontend/base/default/layout/catalog.xml#L228).
/app/code/local/Lbb/Catalog/etc/config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Lbb_Catalog>
<version>0.1.0</version>
</Lbb_Catalog>
</modules>
<global>
<blocks>
<catalog>
<rewrite>
<product_view_options_type_select>Lbb_Catalog_Block_Product_View_Options_Type_Select</product_view_options_type_select>
</rewrite>
</catalog>
</blocks>
</global>
</config>
I get this code from a working example, so it should work
/app/code/local/RWS/CustomOptions/Options/Type/Select.php
<?php
class RWS_CustomOptions_Options_Type_Select extends Mage_Catalog_Block_Product_View_Options_Abstract
{
public function getValuesHtml()
{
.....
/app/code/local/RWS/CustomOptions/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<RWS_CustomOptions>
<version>0.1.0</version>
</RWS_CustomOptions>
</modules>
<global>
<blocks>
<catalog>
<rewrite>
<product_view_options_type_select>RWS_CustomOptions_Options_Type_Select</product_view_options_type_select>
</rewrite>
</catalog>
</blocks>
</global>
</config>
/app/etc/modules/RWS_CustomOptions.xml
<?xml version="1.0"?>
<config>
<modules>
<RWS_CustomOptions>
<active>true</active>
<codePool>local</codePool>
</RWS_CustomOptions>
</modules>
<config>
To test, add a (simple) product in magento admin with a custom select option, the go product detail/view page.
This is my activation file,
in app/etc/modules/My_Test.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<My_Test>
<active>true</active>
<codePool>local</codePool>
</My_Test>
</modules>
</config>
This is my config file in app/code/local/MY/Test/etc/config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<global>
<helpers>
<my_test>
<class>My_Test_Helper</class>
</my_test>
</helpers>
<models>
<mytest>
<class>My_Test_Model</class>
</my_test>
</models>
<blocks>
<my_test>
<class>My_Test_Block</class>
</my_test>
</blocks>
</global>
<frontend>
<routers>
<my_test>
<use>standard</use>
<args>
<module>My_Test</module>
<frontName>test</frontName>
</args>
</my_test>
</routers>
</frontend>
</config>
This is my controllers code
in app/core/local/My/Test/controllers/IndexController.php
<?php
class My_Test_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
echo "This is the Module MyTest";
}
}
Now when i am giving the url
176.58.99.99/herbal/index.php/test/index/index
176.58.99.99/herbal/index.php/test/
176.58.99.99/herbal/test/index/index
176.58.99.99/herbal/test/
Its showing 404 error
You say your controller is located in app/core/local/My/Test/controllers/IndexController.php while it should be placed as followed: app/code/local/My/Test/controllers/IndexController.php
I had the same problem, but in my case it was about file permissions. Make sure that your files and directories have the proper access permissions, if not, magento will never be able to read those files.
I'm trying to overwrite the function couponPostAction in Magento, which is in the cartcontroller.
I created a new local Module Nf_Ajaxcoupon.
this is the config file
<?xml version="1.0"?>
<config>
<modules>
<Nf_Ajaxcoupon>
<version>0.1.0</version>
</Nf_Ajaxcoupon>
</modules>
<global>
<rewrite>
<Nf_Ajaxcoupon_checkout_cart>
<from><![CDATA[#^/checkout/cart/#]]></from>
<to>/Ajaxcoupon/checkout_cart/</to>
</Nf_Ajaxcoupon_checkout_cart>
</rewrite>
</global>
<frontend>
<routers>
<Nf_Ajaxcoupon>
<use>standard</use>
<args>
<module>Nf_Ajaxcoupon</module>
<frontName>Ajaxcoupon</frontName>
</args>
</Nf_Ajaxcoupon>
</routers>
</frontend>
</config>
This is my module activation:
<?xml version="1.0"?>
<config>
<modules>
<Nf_All>
<active>true</active>
<codePool>local</codePool>
</Nf_All>
</modules>
</config>
This is my CartController.php file:
<?php
require_once 'Mage/Checkout/controllers/CartController.php';
class Nf_Ajaxcoupon_Checkout_CartController extends Mage_Checkout_CartController
{
function couponPostAction()
{
var_dump($_POST);
die('local');
}
}
?>
I can't understand why its not calling the local controller, when I go to system->configuration->advanced I see it is enabled.
Any suggestions why its not working or ways to debug it?
Thanks
This is the proper way to override a controller in config inside frontend node
<routers>
<checkout>
<args>
<modules>
<Nf_Ajaxcoupon before="Mage_Checkout">Nf_Ajaxcoupon_Checkout</Nf_Ajaxcoupon>
</modules>
</args>
</checkout>
</routers>
also are you sure that your configure file would not need to be for Nf_Ajaxcoupon not to Nf_All
<?xml version="1.0"?>
<config>
<modules>
<Nf_Ajaxcoupon>
<active>true</active>
<codePool>local</codePool>
</Nf_Ajaxcoupon>
</modules>
</config>