1. Create your modulefolders and files
-
Magento/app/code/local/MyNameSpace/MyModule/etc/config.xml
-
Magento/app/code/local/MyNameSpace/MyModule/ controllers/Checkout/Cart Controller.php
-
Magento/app/etc/modules/MyNameSpace_All.xml
2. Edit/etc/config.xml |
Go to Magento/app/code/local/MyNameSpace/MyModule/etc/config.xmland paste the following xml into it (comments I’m not a 100% sureabout are ending with “(?)”):
-
<?xml version="1.0"?>
-
<config>
-
<modules> -
<MyNameSpace_MyModule> -
<version>0.1.0 </version> -
</MyNameSpace_MyModule> -
</modules> -
<global> -
<!-- This rewrite rulecould be added to the database instead--> -
<rewrite> -
<!-- This is an identifier for yourrewrite that should be unique--> -
<!-- THIS IS THE CLASSNAME IN YOUR OWNCONTROLLER--> -
<mynamespace_mymodule_checkout_cart> -
<from> <![CDATA[#^/checkout/cart/#]]> </from> -
<!-- -
- mymodulematches the router frontname below -
-checkout_cart matches the path to your controller -
-
Considering the router below, "/mymodule/checkout_cart/" willbe -
"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 overloadingsuch stuff (?) -
--> -
<frontend> -
<routers> -
<mynamespace_mymodule> -
<!-- shouldbe 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> -
</config>
[by Hendy: The above didn’t work for me when I override catalog/product controller. I had to use:
-
<from> <![CDATA[#^catalog/product/#]]> </from> -
<to>mymodule/my controller </to>
(notice the missing leading slash)]
by AxelH: Since Magento 1.3 youcan simply add your module to the frontend router. Rewrites are notneccessary any more:
-
<?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> -
</config>
Please note that before=”Mage_Checkout” will load yourcontroller first if available andfallback to Magento’s if not.
[Edit by lichal: For me this code doesn’t work, because thecontroller is in the folder (notethe bold folder): ‘Magento/app/code/local/MyNameSpace/MyModule/controllers/Checkout/CartController.php’.In order to fix it the line 14:
-
<MyNameSpace_MyModulebefore="Mage_Checkout">MyNameSpace_MyModule </MyNameSpace_MyModule>
Has to be:
-
<MyNameSpace_MyModulebefore="Mage_Checkout">MyNameSpace_MyModule_Checkout </MyNameSpace_MyModule>
end Edit by lichal]
3. Edit /controllers/Checkout/CartController.php |
Paste the following php code into Magento/app/code/local/MyNameSpace/MyModule/controllers/Checkout/CartController.php(the only change we’re doing to the indexAction() is adding anerror_log() message):
-
<?php
-
# Controllers are not autoloaded so we will haveto do it manually:
-
require_once 'Mage/Checkout/controllers/CartController.php';
-
classMyNameSpace_MyModule_Checkout_Cart Controller extendsMage_Checkout_Cart Controller
-
{
-
# Overloaded indexAction -
public functionindexAction ( ) -
{ -
# Just tomake sure -
error_log ( 'Yes, I did it!' ); -
parent:: indexAction ( ); -
} -
}
4. Edit Magento/app/etc/modules/MyNameSpace_All.xml |
(This is to activate your module)
-
<?xml version="1.0"?>
-
<config>
-
<modules> -
<MyNameSpace_MyModule> -
<active>true </active> -
<codePool>local </codePool> -
</MyNameSpace_MyModule> -
</modules> -
</config>
[Edit 2009-07-26 by PhilFreo: Steps 1-4 alone were sufficientfor me to overload methods from CartController. I’d like to see some clarificationon exactly what steps 5+ are doing and when they are needed.]
[Edit 2009-07-29 by hexdoll: used steps 1-4 to override the customer/account controller, the error_log occurs but theexpected interface templates are not shown]
5. Edit Magento/app/design/frontend/[myinterface]/[mytheme]/layout/checkout.xml |
Add the following to use the same update handle as before:
-
<mynamespace_mymodule_checkout_cart_index>
-
<update handle="checkout_cart_index"/> -
</mynamespace_mymodule_checkout_cart_index>
(Note that these tags seem to be case sensitive. Try using alllowercase if this isn’t working for you)
[by Hendy: When I overridecatalog/product/view using the method described in this Wikior here, I didn’t have to do the above. However,when using the 'cms way', I had to update the handlemanually.]
6. The above item do not worked for me (updated: 2009-02-19 by:Jonathan M Carvalho) |
After loose so many hours I discovery that the file to change is“Magento/app/design/frontend/[myinterface]/[mytheme]/layout/mymodule.xml”
Update 2009-06-17 by Gabriiiel : added the good syntax(mynamespace_mymodule_checkout_cart_index)
Add the following lines:
-
<mynamespace_mymodule_checkout_cart_index>
-
<update handle="checkout_cart_index"/> -
</mynamespace_mymodule_checkout_cart_index>
Using version 1.2.1
7. Point your browser to/checkout/cart/ |
Take a look in your php error log and you should find ‘Yes, Idid it!’.
8. You need to get extra precise with the rewrite regularexpression cause this causes a very hard time. In thispart. |
<from><![CDATA[#^/checkout/cart/#]]></from>