Magento - override Mage_Customer Address controller - magento

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>

Related

Magento 1.9.2.4 404 with custom controller

I've got module: local/Zzepish/Example.
etc/config.xml:
<global>
<models>
<example>
<class>Zzepish_Example_Model</class>
</example>
</models>
<helpers>
<example>
<class>Zzepish_Example_Helper</class>
</example>
</helpers>
<models>
<example>
<class>Zzepish_Example_Model</class>
</example>
</models>
<blocks>
<example>
<class>Zzepish_Example_Block</class>
</example>
</blocks>
</global>
<frontend>
<routers>
<example>
<use>standard</use>
<args>
<module>Zzepish_Example</module>
<frontName>example</frontName>
</args>
</example>
</routers>
</frontend>
app/etc/modules/Zzepish_Example.xml
<modules>
<Zzepish_MyModule>
<active>true</active>
<codePool>local</codePool>
<depends />
</Zzepish_MyModule>
</modules>
controller in Zzepish/Example/controllers/IndexController.php :
class Zzepish_Example_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
echo 'Hello!';
}
}
But, when i go to my_website/example , my_website/example/index/index it redirects me to 404.
problem is in
app/etc/modules/Zzepish_Example.xml update with following
<modules>
<Zzepish_Example>
<active>true</active>
<codePool>local</codePool>
<depends />
</Zzepish_Example>
</modules>

Extending Mage_Catalog_Block_Navigation

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.

Magento : Create admin module

I have a problem. I following guideline but it doesn't work. I don't know debug how. Please tell me the way resolve problem.
This is HS_Imagepro.xml in etc/modules/ folder
<?xml version="1.0"?>
<config>
<modules>
<HS_Imagepro>
<active>True</active>
<codePool>core</codePool>
</HS_Imagepro>
</modules>
</config>
This is config.xml in HS/Imagepro/etc folder
<?xml version="1.0"?>
<config>
<modules>
<HS_Imagepro>
<version>0.1.1</version>
</HS_Imagepro>
</modules>
<admin>
<routers>
<adminhtml>
<use>admin</use>
<args>
<modules>
<module>HS_Imagepro</module>
<frontName>imagepro</frontName>
</modules>
</args>
</adminhtml>
</routers>
</admin>
<adminhtml>
<menu>
<imagepro_menu translate="title" module="imagepro">
<title>ImagePro</title>
<sort_order>9999</sort_order>
<children>
<first_page module="imagepro">
<title>Our First Page</title>
<action>imagepro/index/index</action>
</first_page>
</children>
</imagepro_menu>
</menu>
</adminhtml>
<global>
<helpers>
<imagepro>
<class>HS_Imagepro_Helper</class>
</imagepro>
</helpers>
</global>
</config>
This is IndexController.php in HS/Imagepro/controllers/
<?php
class HS_Imagepro_IndexController extends Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
}
?>
The result is the page not found.
If The following right guideline, access link http://localhost/magento/index.php/imagepro/ will appear admin login screen.
In ,HS_Imagepro.xml file the test TRUE Should be true.
routing code Wrong in config.xml
<?xml version="1.0"?>
<config>
<modules>
<HS_Imagepro>
<version>0.1.1</version>
</HS_Imagepro>
</modules>
<admin>
<routers>
<!-- Includes our controller, so when we add the adminhtml menu item below, it is found! -->
<adminhtml>
<args>
<modules>
<imagepro before="Mage_Adminhtml">HS_Imagepro_Adminhtml</imagepro>
</modules>
</args>
</adminhtml>
</routers>
</admin>
</config>
Also controller file and path name is wrong
HS/Imagepro/controllers/Adminhtml/ImageproController.php
<?php
class HS_Imagepro_Adminhtml_ImageproController extends Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
}
?>
Testing url yourhost/magento/index.php/admin/imagepro
More details on http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/custom_module_with_custom_database_table#directory_additions
and frontend module http://www.amitbera.com/create-an-magento-extension-with-custom-database-table/

Override Topmenu.php in magento

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
{
}

not load controller in magento, why?

config.xml
<?xml version="1.0"?>
<config>
<modules>
<Asgard_New>
<version>1.6.0.0</version>
</Asgard_New>
</modules>
<global>
<models>
<asgardnew>
<class>Asgard_New_Model</class>
</asgardnew>
</models>
<helpers>
<asgardnew>
<class>Asgard_New_Helper</class>
</asgardnew>
</helpers>
</global>
<frontend>
<routers>
<asgardnew>
<use>standard</use>
<args>
<module>Asgard_New</module>
<frontName>new</frontName>
</args>
</asgardnew>
</routers>
</frontend>
</config>
Asgard_New.xml
<?xml version="1.0"?>
<config>
<modules>
<Asgard_New>
<active>true</active>
<codePool>local</codePool>
</Asgard_New>
</modules>
</config>
IndexController.php
<?php
class Asgard_New_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
echo "Hello, magento!!";
}
public function helloAction()
{
echo "Hello, action!!";
}
public function layoutAction()
{
$xml = $this->loadLayout()->getLayout()->getUpdate()->asString();
$this->getResponse()->setHeader("Content-Type", "text/plain")->setBody($xml);
Mage::log($xml, Zend_Log::INFO, 'layout_log', true);
}
public function defaultAction()
{
$this->loadLayout()->renderLayout();
}
}
?>
Modul -> local/Asgard I have folders with same code Test ans New
http://magento/test/index/index
http://magento/new/index/index
Not work, last two days works, but today i try created a own package and theme this is stop working. Why its may happened, guys? Thanks!
Try to replace asgardnew with new
<frontend>
<routers>
<new>
<use>standard</use>
<args>
<module>Asgard_New</module>
<frontName>new</frontName>
</args>
</new>
</routers>
</frontend>

Resources