我如何覆盖“addAction()” app\code\core\Mage\Checkout\controllers 下的函数

发布于 2024-10-26 10:56:53 字数 205 浏览 1 评论 0原文

当产品添加到购物车时,我试图将一些数据添加到会话变量...

我尝试将“app\code\core\Mage\Checkout\controllers”下的“CartController.php”复制到 “local\Mage\Checkout\controllers”,但它实际上并没有覆盖控制器..

有人能给我一些关于这个的提示吗..?

多谢。

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 "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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜巴黎 2024-11-02 10:56:53

您可以创建一个“事件观察服务器”来触发事件。

以下文件夹:

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

在 /EventTest/Model 目录下创建一个文件,如 myMagento_EventTest.xml 并放置以下内容:

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

创建 /EventTest/etc 文件夹下的 config.xml 文件添加以下内容:

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

在 /EventTest/Model 目录下创建模型类文件observer.php 并添加以下内容

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

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
}
}
白昼 2024-11-02 10:56:53

我发现这个 ,这使我们能够覆盖 CartController.php addAction() 函数...这正是我所需要的。

希望这能帮助有需要的人。

巴兰

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文