-1

I am overriding the Checkout Controller. For that I created my package Easylife and created the Checkout module. The code for that is below:

magento\app\etc\modules\Easylife_Checkout.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Easylife_Checkout>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Checkout/>
            </depends>
        </Easylife_Checkout>
    </modules>
</config>

and magento\app\code\local\Easylife\Checkout\controllers\CartController.php

<?php

class Easylife_Checkout_CartController extends Mage_Checkout_CartController
{

    public function indexAction()
    {
        $this
            ->loadLayout()
            ->_initLayoutMessages('checkout/session')
            ->_initLayoutMessages('catalog/session')
            ->getLayout()->getBlock('head')->setTitle($this->__('Shopping Cart'));

        if(!Mage::getSingleton('customer/session')->isLoggedIn())
        {
            $this->_redirect('customer/account/login'); // add login form
        }

        $this->renderLayout();
    }

}

and magento\app\code\local\Easylife\Checkout\etc\config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Easylife_Checkout>
            <version>1.6.0.1</version>
        </Easylife_Checkout>
    </modules>
    <frontend>
        <routers>
            <checkout>
                <use>standard</use>
                <args>
                    <module>Easylife_Checkout</module>
                    <frontName>checkout</frontName>
                </args>
            </checkout>
        </routers>
    </frontend>
</config>

but it's returning an error Class 'Mage_Checkout_CartController' not found when I hit the cart link button in header link.

Is this procedure correct?

If this is wrong can you tell me how to override that?

Thanks.

1

You need to include this line in app\code\local\Easylife\Checkout\controllers\CartController.php before the class declaration.

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

This is needed because the controller classes are not autoloaded like the rest of the classes are.
You may also want to change the way you defined your frontend router. You might get in trouble if you just declare the same route name for 2 modules.
So change this:

<frontend>
    <routers>
        <checkout>
            <use>standard</use>
            <args>
                <module>Easylife_Checkout</module>
                <frontName>checkout</frontName>
            </args>
        </checkout>
    </routers>
</frontend>

To this:

<frontend>
    <routers>
        <checkout>
            <args>
                <modules>
                    <Easylife_Checkout before="Mage_Checkout">Easylife_Checkout</Easylife_Checkout>
                </modules>
            </args>
        </checkout>
    </routers>
</frontend>

This will tell magento to look for a controller when the request starts with checkout/ in your module before looking in the Mage_Checkout module.

  • now displaying checkout\cart page. see my posted question CartController.php I have override if user not login I redirected login this is not working why? – Magento Nav Feb 11 '14 at 10:39
  • ok thank you working fine I had small mistake. now I correct my self. – Magento Nav Feb 11 '14 at 10:44
  • Erm, </Crap_Mod2>?? – Jongosi Mar 31 '14 at 20:41
  • @jongosi...oups. sorry about that. Copy paste mistake :). – Marius Mar 31 '14 at 21:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.