且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Shopware中向帐户控制器添加操作

更新时间:2023-09-21 21:07:58

扰流器:更换控制器

没有比替换整个控制器并扩展其功能更干净的方法了,因此它几乎与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.