Magento Forwarding Controller

I would like to do the above. Ive redefined many files in the past ... block, model, helper ... but this one did not slip me.

Can anyone see what I'm doing wrong here: (ive edited this code ... to include some recommendations now ...)

Here is my folder structure (2 controller places as a test):

/Idigital/Idgeneral/etc/config.xml /Idigital/Idgeneral/controllers/Checkout/CartController.php /Idigital/Idgeneral/controllers/CartController.php 

Here is my config.xml:

 <?xml version="1.0"?> <config> <modules> <idigital_idgeneral> <version>0.1.0</version> </idigital_idgeneral> </modules> <global> <blocks> <idgeneral><class>Idigital_Idgeneral_Block</class></idgeneral> </blocks> </global> <frontend> <routers> <checkout> <use>standard</use> <args> <modules> <Idigital_Idgeneral before="Mage_Checkout">Idigital_Idgeneral_Checkout</Idigital_Idgeneral> </modules> </args> </checkout> </routers> <layout> <updates> <idgeneral> <file>idigital.xml</file> </idgeneral> </updates> </layout> </frontend> </config> 

I checked my controller test file in two places. And here is at the top of my FIRST file:

 require_once 'Mage/Checkout/controllers/CartController.php'; class Idigital_Idgeneral_Checkout_CartController extends Mage_Checkout_CartController { public function testAction() { var_dump('inside checkout/cart/test');exit; } /** * Add product to shopping cart action */ public function addAction() { blah... } 

My second controller:

 require_once 'Mage/Checkout/controllers/CartController.php'; class Idigital_Idgeneral_CartController extends Mage_Checkout_CartController { public function testAction() { var_dump('inside cart/test');exit; } /** * Add product to shopping cart action */ public function addAction() { blah... } 

When I am: / checkout / cart / add Im directed to the mage controller ... not my local one. (I have var_dump stmts in each ... so I see which one is running).

When I visit / check / cart / test - I get 404 When I visit / cart / add or cart / test - I get 404 when I visit idgeneral / cart / test or idgeneral / cart / add - I get 404

+6
source share
5 answers
  • Create folders and files for your module

     app/code/local/MyNameSpace/MyModule/etc/config.xml app/code/local/MyNameSpace/MyModule/controllers/Checkout/CartController.php app/etc/modules/MyNameSpace_All.xml 
  • Modify / etc / config.xml and create an application / code / local / MyNameSpace / MyModule / etc / config.xml with the following contents:

     <?xml version="1.0"?> <config> <modules> <MyNameSpace_MyModule> <version>0.1.0</version> </MyNameSpace_MyModule> </modules> <global> <!-- This rewrite rule could be added to the database instead --> <rewrite> <!-- This is an identifier for your rewrite that should be unique --> <!-- THIS IS THE CLASSNAME IN YOUR OWN CONTROLLER --> <mynamespace_mymodule_checkout_cart> <from><![CDATA[#^/checkout/cart/#]]></from> <!-- - mymodule matches the router frontname below - checkout_cart matches the path to your controller Considering the router below, "/mymodule/checkout_cart/" will be "translated" to "/MyNameSpace/MyModule/controllers/Checkout/CartController.php" (?) --> <to>/mymodule/checkout_cart/</to> </mynamespace_mymodule_checkout_cart> </rewrite> </global> <!-- If you want to overload an admin controller this tag should be <admin> instead, or <adminhtml> if youre overloading such stuff (?) --> <frontend> <routers> <mynamespace_mymodule> <!-- should be set to "admin" when overloading admin stuff (?) --> <use>standard</use> <args> <module>MyNameSpace_MyModule</module> <!-- This is used when "catching" the rewrite above --> <frontName>mymodule</frontName> </args> </mynamespace_mymodule> </routers> </frontend> 

    Note. The above does not work for me when I redefine the product directory / controller. I had to use:

      <from><![CDATA[#^catalog/product/#]]></from> <to>mymodule/mycontroller</to> 

    (note the missing leading slash)

    Since Magento 1.3 you can simply add your module to an external router. Repeated appeals are not required:

      <?xml version="1.0" encoding="UTF-8"?> <config> <modules> <MyNameSpace_MyModule> <version>0.1.0</version> </MyNameSpace_MyModule> </modules> <frontend> <routers> <checkout> <args> <modules> <MyNameSpace_MyModule before="Mage_Checkout">MyNameSpace_MyModule</MyNameSpace_MyModule> </modules> </args> </checkout> </routers> </frontend> 

    Note that before="Mage_Checkout" first load your controller, if available, and return to Magentos if not.

    If the controller is in a different folder, you will have to change the code:
    app/code/local/MyNameSpace/MyModule/controllers/Checkout/CartController.php.

Replace

<MyNameSpace_MyModule before="Mage_Checkout">MyNameSpace_MyModule</MyNameSpace_MyModule>

from

  <MyNameSpace_MyModule before="Mage_Checkout">MyNameSpace_MyModule_Checkout</MyNameSpace_MyModule> 
  • Change 'controllers/Checkout/CartController.php'

    Create app/code/local/MyNameSpace/MyModule/controllers/Checkout/CartController.php with the following contents: (the only change in indexAction () adds the error_log () call):

      <?php # Controllers are not autoloaded so we will have to do it manually: require_once 'Mage/Checkout/controllers/CartController.php'; class MyNameSpace_MyModule_Checkout_CartController extends Mage_Checkout_CartController { # Overloaded indexAction public function indexAction() { # Just to make sure error_log('Yes, I did it!'); parent::indexAction(); } } 
    • Change 'app/etc/modules/MyNameSpace_All.xml' (This is necessary to activate your module)

      true local

  • Change the 'app/design/frontend/[myinterface]/[mytheme]/layout/checkout.xml' and add the following to use the same update descriptor as before:

      <mynamespace_mymodule_checkout_cart_index> <update handle="checkout_cart_index"/> </mynamespace_mymodule_checkout_cart_index> 

    (Note that these tags are case sensitive. Try using all lowercase letters if this doesn't work for you)

    [by Hendy: When I redefine the catalog / product / view using the method described in this Wiki or here, I should not have done the above. However, when using the "cms way", I had to manually update the descriptor.]

    The above item did not work for me (2009-02-19 by Jonathan M Carvalho)

    I found that the file to change is: app / design / frontend / [myinterface] / [mytheme] /layout/mymodule.xml

    Add the following lines:


    • Point your browser at / checkout / cart / In your PHP error log you should find "Yes, I did it!".

    You need to be more precise with regex rewriting because errors are very hard to find.

+7
source
 <Idigital_Idgeneral before="Mage_Checkout">Idgeneral_Checkout</Idigital_Idgeneral> 

Must be

 <Idigital_Idgeneral before="Mage_Checkout">Idigital_Idgeneral_Checkout</Idigital_Idgeneral> 

or try moving your custom controller to

 ../Idigital/Idgeneral/controllers/CartController.php 

and use

 <Idigital_Idgeneral before="Mage_Checkout">Idigital_Idgeneral</Idigital_Idgeneral> 

There is an error in your <modules> tag. It should be:

 <config> <modules> <idigital_idgeneral> <version>0.1.0</version> </idigital_idgeneral> </modules> <global> ... </global> <frontend> .... </frontend> ... </config> 

ie <modules> must not be inside <global>

Here is a good tutorial on how to reset the configuration tree that Magento sees as XML: http://alanstorm.com/magento_config

+6
source

I leave it here for the next poor developer, forced to work with this jalopy. Most of the instructions here are from magento docs , which, like its source, are a distorted labyrinth of the wrong direction. Enough complaints ...

This worked for me in version 1.8

Create a namespace and module: / application / code / local / MyNameSpace / MyModule

Create your module configuration: /app/code/local/MyNameSpace/MyModule/etc/config.xml

 <?xml version="1.0" ?> <config> <modules> <MyNameSpace_MyModule> <version>0.1.0</version> </MyNameSpace_MyModule> </modules> <frontend> <routers> <checkout> <args> <modules> <MyNameSpace_MyModule before="Mage_Checkout">MyNameSpace_MyModule_Checkout</MyNameSpace_MyModule> </modules> </args> </checkout> </routers> </frontend> 

Create your controller: /app/code/local/MyNameSpace/MyModule/controllers/Checkout/CartController.php

 <?php require_once Mage::getModuleDir('controllers', 'Mage_Checkout').DS.'CartController.php'; class MyNameSpace_MyModule_Checkout_CartController extends Mage_Checkout_CartController { public function indexAction() { // /var/log/debug.log should log the output Mage::log('cart index override', null, 'debug.log'); // Call the parent class parent::indexAction(); } } 

Include the new module: / app / etc / modules / MyNameSpace _All.xml

 <?xml version="1.0" ?> <config> <modules> <MyNameSpace_MyModule> <active>true</active> <codePool>local</codePool> </MyNameSpace_MyModule> </modules> </config> 

That is all that is needed. Now go to the celebration, you just polished the shit!;)

+3
source

This is a small notice along the way to enable the controller.

This includes a path that can cause errors if Magento Compiler mode is enabled.

 require_once 'Mage/Checkout/controllers/CartController.php'; 

Useful instead

 require_once Mage::getModuleDir('controllers', 'Mage_Checkout').DS.'CartController.php'; 

It will be safer.

+1
source

Well ... this is WONT overriding the basket controller.

So, I used the REWRITE URL in VIEWING THE PRODUCT ... from this link ... at the bottom of the article. They say this is the right method ...

http://www.excellencemagentoblog.com/magento-add-product-to-cart-ajax

 if(!url){ url = jQuery('#product_addtocart_form').attr('action'); } url = url.replace("checkout/cart","idgeneral/cart"); 

It worked for me. Lets me crack. Basically calls the MY controller .. instead of the control controller.

Thanks for the help ROSCIUS ... appreciated.

I also had to change my configuration .... my router section now looks like this:

 <routers> <!-- THIS PART REGISTERS OUR CONTROLLERS FOLDER FOR USE --> <idgeneral> <use>standard</use> <args> <module>Idigital_Idgeneral</module> <frontName>idgeneral</frontName> </args> </idgeneral> <!-- THIS PART WONT WORK TO OVERWRITE OUR MAGE CONTROLLER --> <checkout> <use>standard</use> <args> <modules> <Idigital_Idgeneral before="Mage_Checkout">Idigital_Idgeneral_Checkout</Idigital_Idgeneral> </modules> </args> </checkout> </routers> 
0
source

Source: https://habr.com/ru/post/919789/


All Articles