Need help buying now? +48-22-219-5163 +1-917-720-3250
My Cart

Your Cart is Empty

Need help buying now?
+48-22-219-5163 +1-917-720-3250

How to change Magento Controller

How to change Magento Controller

Magento functionality often requires different modifications and corrections, everything depends on your personal needs and skills. It is very important to know how to change the Magento controller ‘Shopping cart’ and this is what we are going to discuss in this article.

Why is it necessary to change the controller?

In the process of a web store development it is necessary to take into account the requirements of potential customers. We need to not only follow the general rules of usability but also understand what our target audience needs. The file Cart.php is responsible for the ‘shopping cart’ which customer sees. And the customer would appreciate if they can see not only the products in their cart, but the price of each item separately as well as their total cost.

If you do not have a special Magento extension then you need to change the standard product output in the cart with the help of the site editor. More exactly, you need to edit a specific Action in Cart.php.

In order to create a Magento module that will further be responsible for the work of Magento controller, please follow the instructions below:

1. Create a folder named ‘My’, it is a folder for developers. It should be located at the following path: open ‘app’, then move to ‘code’, then to ‘local’;

2. Now create a folder called ‘Checkout’. It will contain the module once it is complete. Place it into ‘app/code/local/My’ folder;

3. Now you need to create folders for your Magento module configuration file and the controller. Go back to ‘Checkout’ folder and create a subfolder ‘etc’ inside it. Here you also need to create a subfolder called ‘controllers’ and inside it create another subfolder called ‘Checkout’. Be very attentive at this step, because if you do something wrong you will not be able to proceed;

4. Now you need to create a configuration file that will be responsible for the module operation. Inside ‘etc’ folder create a file called config.xml. Verify that it is located at app/code/local/My/Checkout/etc folder. The file must contain the following code:

<?xml version="1.0"?>
<config>
<modules>
<My_Checkout>
<version>0.0.1</version>
</My_Checkout>
</modules>
<frontend>
<routers>
<checkout>
<args>
<modules>
<My_Checkout before="Mage_Checkout">My_Checkout_Checkout</My_Checkout>
</modules>
</args>
</checkout>
</routers>
</frontend>
</config>

 

how to change the Magento controller

5. This code is responsible for correct functionality of all modules. Also, at this step of programming you need to specify that the controller you are creating must be loaded before the standard Mage_Checkout Magento.

6. Then, create a file ‘CartController.php’ inside Checkout folder. At this moment, rewriting of the standard controllers begins.

Put the following PHP code into this file:

require_once("Mage/Checkout/controllers/CartController.php");
/**
* Shopping cart controller
*/
class My_Checkout_Checkout_CartController extends Mage_Checkout_CartController
{
/**
* Shopping cart display action
*/
public function indexAction()
{
die('hello magento');
}
}

 

7. When all steps are complete you need to enable your module. Go to app/etc/modules and create a file My_Checkout.xml. Put the following code inside this file:

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

 

Code is taken from www.magefast.com

After that, do not forget to flush Magento cache. Now the only thing left is to check the functionality of your module. You can do this by going to the shopping cart on your site. If you have any problems with changing Magento controller on your own, please consult with GoMage programmers. We will also appreciate if you share your variants of resolving this task in the comments to this article.

Newsletter