开发者

How do i override the "addAction()" funciton under app\code\core\Mage\Checkout\controllers

开发者 https://www.devze.com 2023-02-19 18:14 出处:网络
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.p开发者_C百科hp\" under \"app\\code\\core\\Mage\\Checkout\\cont

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.p开发者_C百科hp" under "app\code\core\Mage\Checkout\controllers" to "local\Mage\Checkout\controllers" but its not actually overriding the controller..

Could anyone give me some hint on this..?

Thanks a lot.


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
}
}


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

0

精彩评论

暂无评论...
验证码 换一张
取 消