扩展 magento 核心控制器 (Checkout/OnepageController) [英] Extend magento core controller (Checkout/OnepageController)

查看:18
本文介绍了扩展 magento 核心控制器 (Checkout/OnepageController)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在覆盖核心控制器时遇到问题.我想添加一个新函数,但只有在核心文件 (code/core/checkout/controllers/onepagecontroller.php) 中才有效.

I am having problems while overriding a core controller. I want to add a new function but it only works if I do it in the core file (code/core/checkout/controllers/onepagecontroller.php).

我已经关注了一些帖子,但它不起作用.其中一些是:

I have followed some post, but it's not working. Some of them are:

(我无法添加更多链接,抱歉)

(I can't add more links, sorry)

我不知道发生了什么……也许你可以帮我;)

I don't know what is happening... maybe you can help me ;).

我使用的是 magento 1.5,我有这 3 个文件:

I'm using magento 1.5 and I have this 3 files:

local -> Arias -> CoreExtended -> etc -> config.xml

local -> Arias -> CoreExtended -> etc -> config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Arias_CoreExtended>
            <version>0.1.0</version>
        </Arias_CoreExtended>
    </modules>

    <frontend>
        <routers>
            <checkout>
                <args>
                    <modules>
                        <Arias_CoreExtended before="Mage_Checkout">Arias_CoreExtended_Checkout</Arias_CoreExtended>
                    </modules>
                </args>
            </checkout>
        </routers>
    </frontend>
</config>

<小时>

app -> etc -> modules -> Arias_CoreExtended.xml


app -> etc -> modules -> Arias_CoreExtended.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Arias_CoreExtended>
            <active>true</active>
            <codepool>local</codepool>
        </Arias_CoreExtended>
    </modules>
</config>

<小时>

local -> Arias -> CoreExtended -> 控制器 -> Checkout -> OnepageController.php


local -> Arias -> CoreExtended -> controllers -> Checkout -> OnepageController.php

<?php

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

class Arias_CoreExtended_Checkout_OnepageController extends Mage_Checkout_OnepageController
{
    public function collectAction()
    {
        echo 'WTF?';
    }

    public function indexAction()
    {
        echo "This controller has been overridden.";
    }
}

提前感谢您的时间,问候.

Thanks in advance for your time, regards.

推荐答案

我会首先镜像你正在覆盖的控制器的相同目录结构,所以在这种情况下更改:local/Arias/CoreExtended/controllers/Checkout/OnepageController.phplocal/Arias/CoreExtended/controllers/OnepageController.php

I would first mirror the same directory structure of the controller you are overwriting, so in this case change: local/Arias/CoreExtended/controllers/Checkout/OnepageController.php to local/Arias/CoreExtended/controllers/OnepageController.php

您应该小写您的命名空间/模块名称,并且您需要删除 _Checkout 因为它通常会覆盖控制器,并且将查找模块中存在的任何内容以使用它们,如果不是的话回到标准.正确的代码是:

You should lowercase your namespace/module name and you need to remove _Checkout as it is overwriting the controllers in general, and will look up any that exist in the module to use them instead if not fall back to standard. The correct code would be:

<arias_coreextended before="Mage_Checkout">Arias_CoreExtended</arias_coreextended>

我已经成功地使用这个确切的设置来覆盖 Onepage 控制器!

I have used this exact setup with success to overwrite the Onepage controller!

这篇关于扩展 magento 核心控制器 (Checkout/OnepageController)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆