如何在Shopware中向帐户控制器添加操作 [英] How to add an Action to Account Controller in Shopware

查看:95
本文介绍了如何在Shopware中向帐户控制器添加操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何向Shopware中的现有Controller添加自定义操作?

How to add a custom action to an existing Controller in Shopware?

示例(网址结构):

/account/bonus
/account/custom
/account/...

通常,为此目的创建一个新的控制器更容易,更清洁,但是在某些情况下有必要.

Usually it's easier and cleaner to create a new controller for that purpose, but in some cases it's necessary.

推荐答案

扰流器:更换控制器

没有比替换整个控制器并扩展其功能更干净的方法了,因此它几乎与Shopware的钩子一样干净.

There is no cleaner way than to replace the whole controller and extend it's functionality, so it's nearly as clean as Shopware's hooks.

指南

将新的订阅者添加到您的插件

Add a new Subscriber to your Plugin

class AccountSubscriber implements SubscriberInterface
{
    /**
     * @return array
     */
    public static function getSubscribedEvents()
    {
        return array(
            'Enlight_Controller_Dispatcher_ControllerPath_Frontend_Account' => 'getAccountController'
        );
    }

    /**
     * @return string
     */
    public function getAccountController()
    {
        return $this->getPath() . '/Controllers/Frontend/AccountExtended.php';
    }

    /**
     * @return string
     */
    public function getPath()
    {
        $plugin = Shopware()->Container()->get('kernel')->getPlugins()['AcmeYourPlugin'];

        return $plugin->getPath();

    }
}

缺点

不幸的是,某些控制器具有影响逻辑的私有方法.就像客户控制器一样.因此,并非总是可以简单地扩展控制器.

Unfortunately some controller have private methods which impact the logic. Like the Account Controller. So it's not always possible to simply extend the controller.

最后,尝试添加具有新路由的新控制器.更简单,更干净.

In the end, try to add a new controller with a new route. It's easier, and cleaner.

这篇关于如何在Shopware中向帐户控制器添加操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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