How do i override the “addAction()” funciton under appcodecoreMageCheckoutcontrollers

I am trying to add some data to a session variable when a product is added to the shopping cart…

I tried copying the “CartController.php” under “appcodecoreMageCheckoutcontrollers” to
“localMageCheckoutcontrollers” but its not actually overriding the controller..

Could anyone give me some hint on this..?

Thanks a lot.

2 thoughts on “How do i override the “addAction()” funciton under appcodecoreMageCheckoutcontrollers”

  1. You can create an “Event Oberserver” to trigger an event.

    Create the following folders :

    • app/code/local/[myMagento]/EventTest/etc
    • app/code/local/[myMagento]/EventTest/Model

    create a file under /EventTest/Model directory like myMagento_EventTest.xml and put the following :

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

    create config.xml file under /EventTest/etc folder nad put the following :

    <?xml version="1.0"?>
          <config>
            <modules>
              <myMagento_EventTest>
              <version>0.1.0</version>
              </myMagento_EventTest>
            </modules>
            <frontend>
             <events>
                <checkout_cart_product_add_after>
                    <observers>
                       <myMagento_EventTest_Model_Observer>
                          <type>singleton</type>
                          <class>myMagento_EventTest_Model_Observer</class>
                          <method>MyTestMethod</method>
                       </myMagento_EventTest_Model_Observer>
                   </observers>
                </checkout_cart_product_add_after>
            </events>
          </frontend>
         </config> 
    

    create model class file observer.php under the /EventTest/Model directory and put following

    <?php
    
    class myMagento_EventTest_Model_Observer {
    public function MyTestMethod($observer) {
    $event = $observer->getEvent(); //Fetches the current event
    $product = $event->getProduct();
    $eventmsg = "Current Event Triggered : " . $event->getName() . "
    Currently Added Product : " . $product->getName();
    //Adds Custom message to shopping cart
    echo Mage::getSingleton("checkout/session")->addSuccess($eventmsg);
    //Your Custom Logic Here
    //you can use print_r($product) here to get more details
    }
    }
    

  2. I found this , this enables us to override the CartController.php addAction() funciton… This is exaclty i needed.

    Hope this would help someone in need.

    Balan

Leave a Reply

Your email address will not be published. Required fields are marked *