Merchant Stories

Magento Controllers: How to Change For Your Shopping Cart

Sep 17, 2014 2 min read 409 views
Listen audio
Magento Controllers: How to Change For Your Shopping Cart

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 ‘Shopping cart’ controller in Magento ®.

Why is it necessary to change Magento controllers?

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 extension for Magento ® 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 module for Magento ® that will further be responsible for the work of the controller in Magento ®, 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 the configuration file and the controller of your extension for Magento ®. 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 the 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 in 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 in this file:

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

 

The code is taken from www.magefast.com

After that, do not forget to flush the cache in Magento ®. 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 the controller in Magento ® 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.

That's where you contact us!

    By submitting this form you agree to GoMage's Terms of Use and Privacy Policy
    woo-hoo! Now its time to keep checking your inbox, as we will be getting in touch soon. Promise :)
    oops! Thanks. But it seems like some kind of technical issues stop you from meeting GOMAGE. Could you try again?