Magento - local cartcontroller is not working - magento

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>

Related

Magento Checkout OnepageController not getting override

I have searched and implemented many answers from stackoverflow but I am not able to override the controller. The question is quite self-explanatory but I will provide the codes to show what I am doing. Maybe someone can guide me in the right direction:
This is my directory structure
This is my config.xml inside etc folder.
<?xml version="1.0"?>
<config>
<modules>
<Zepcom_Checkout>
<version>0.0.1</version>
</Zepcom_Checkout>
</modules>
<frontend>
<routers>
<checkout>
<args>
<modules>
<Zepcom_Checkout before="Mage_Checkout">Zepcom_Checkout</Zepcom_Checkout>
</modules>
</args>
</checkout>
</routers>
</frontend>
And this is my controller
require_once 'Mage/Checkout/controllers/OnepageController.php';
class Zepcom_Checkout_OnepageController extends Mage_Checkout_OnepageController {
public function indexAction() {
var_dump("custom"); die;
}
.
. // some overriding code here
.
}
I am really stuck and any help would be appreciated. I am doing a dump to verify the calling of the controller but it keeps calling the Core controller.
You will need to declare a router "routeurfrontend" which is actually the route used by Magento to access your controller.
<?xml version="1.0"?>
<config>
<frontend>
<routers>
<zepcom_checkout>
<use>standard</use>
<args>
<module>Zepcom_Checkout</module>
<frontName>zepcom_checkout</frontName>
</args>
</zepcom_checkout>
<checkout>
<args>
<modules>
<Zepcom_Checkout before="Mage_Checkout">Zepcom_Checkout</Zepcom_Checkout>
</modules>
</args>
</checkout>
</routers>
</frontend>
</config>
You are missing the </config> closing tag in your config.xml
<?xml version="1.0"?>
<config>
<modules>
<Zepcom_Checkout>
<version>0.0.1</version>
</Zepcom_Checkout>
</modules>
<frontend>
<routers>
<checkout>
<args>
<modules>
<Zepcom_Checkout before="Mage_Checkout">Zepcom_Checkout</Zepcom_Checkout>
</modules>
</args>
</checkout>
</routers>
</frontend>
</config>

Magento 1: app/code/local not overriding core file

I have copied the "app/code/core/Mage/Customer/controllers/AccountController.php" to "app/code/local/Mage/Customer/controllers/AccountController.php" but it is not overriding the targeted file. what is getting wrong?
Create following files:
1) app/etc/modules/Muk_Account.xml
<?xml version="1.0"?>
<config>
<modules>
<Muk_Account>
<active>true</active>
<codePool>local</codePool>
</Muk_Account>
</modules>
</config>
2) app\code\local\Muk\Account\etc\config.xml
<?xml version="1.0"?>
<config>
<modules>
<Muk_Account>
<version>0.1.0</version>
</Muk_Account>
</modules>
<frontend>
<routers>
<customer>
<use>standard</use>
<args>
<modules>
<Muk_Account before="Mage_Customer">Muk_Account_Customer</Muk_Account>
</modules>
</args>
</customer>
</routers>
</frontend>
</config>
3) app\code\local\Muk\Account\controllers\Customer\AccountController.php
<?php
require_once 'Mage/Customer/controllers/AccountController.php';
class Muk_Account_Customer_AccountController extends Mage_Customer_AccountController
{
public function createPostAction()
{
}
}

Overriding account controller

I try to override function in controller /app/code/core/Mage/Customer/controllers/AccountController.php.
I create module folders:
/app/code/local/Mandarin/SkipLogoutSuccess/etc/config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Mandarin_SkipLogoutSuccess>
<version>0.1.0</version>
</Mandarin_SkipLogoutSuccess>
</modules>
<frontend>
<routers>
<checkout>
<args>
<modules>
<mandarin_skiplogoutsuccess before="Mage_Customer">Mandarin_SkipLogoutSuccess</mandarin_skiplogoutsuccess>
</modules>
</args>
</checkout>
</routers>
</frontend>
</config>
/app/code/local/Mandarin/SkipLogoutSuccess/controllers/AccountController.php
require_once 'Mage/Customer/controllers/AccountController.php';
class Mandarin_SkipLogoutSuccess_AccountController extends Mage_Customer_AccountController
{
public function logoutAction()
{
$this->_getSession()->logout()->setBeforeAuthUrl(Mage::getUrl());
Mage::log("its Allive!", null, 'mygento.log');
$this->_redirectUrl(Mage::getUrl());
}
}
/app/etc/modules/Mandarin_SkipLogoutSuccess.xml
<?xml version="1.0"?>
<config>
<modules>
<Mandarin_SkipLogoutSuccess>
<active>true</active>
<codePool>local</codePool>
</Mandarin_SkipLogoutSuccess>
</modules>
</config>
When I run logoutAction controller is used from core. In my log file I don`t get message.
Where could be the error?
I think you made a copy-paste error:
In your config.xml you reference the namespace "<checkout>" but it should be "<customer>" (and of course the closing tag too)
In your config.xml
<frontend>
<routers>
<customer> <!-- should be customer -->
And in Mandarin_SkipLogoutSuccess.xml
<?xml version="1.0"?>
<config>
<modules>
<Mandarin_SkipLogoutSuccess>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Customer /> <!-- Make sure this is loaded first -->
</depends>
</Mandarin_SkipLogoutSuccess>
</modules>
</config>

I want to know why my Magento Module with only controllers is not working

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.

Overwrite CompareController

I try to override the Core CompareController. Somehow i don't get it done.
I have done some research on the Magento website: http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/how_to_overload_a_controller
But it did not help override the controller.
local/WP/Compare/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<WP_Compare>
<version>0.1.0</version>
</WP_Compare>
</modules>
<global>
<rewrite>
<WP_Compare_Catalog_Product_Compare>
<from><![CDATA[#^/catalog/product/compare/#]]></from>
<to>/compare/catalog/product/compare/</to>
</WP_Compare_Catalog_Product_Compare>
</rewrite>
</global>
</config>
local/WP/Catalog/controllers/Product/CompareController.php
<?php
require_once "Mage/Catalog/controllers/Product/CompareController.php";
class WP_Compare_Catalog_Product_CompareController extends Mage_Catalog_Product_CompareController
{
public function addAction()
{
echo 'Lets GO!';
}
}
?>
Can someone help me with this issue?
Thank you.
Gr.
Lex
This is the solution for my problem.
<?xml version="1.0"?>
<config>
<modules>
<WP_Compare>
<version>0.1.0</version>
</WP_Compare>
</modules>
<frontend>
<routers>
<catalog>
<use>standard</use>
<args>
<modules>
<WP_Compare before="Mage_Catalog">WP_Compare_Catalog</WP_Compare>
</modules>
</args>
</catalog>
</routers>
</frontend>
</config>
You may be need to do something similar to that into your etc.xml:
<frontend>
<routers>
<customer>
<args>
<modules>
<Mymodule_Customer before="Mage_Customer">Mymodule_Customer</Mymodule_Customer>
</modules>
</args>
</customer>
</routers>
</frontend>

Resources