首页 > 解决方案 > 重定向到控制器抛出“不幸的是,出了点问题。”

问题描述

我已经在开发模板中安装了这个插件https://github.com/shopware/swag-docs-storefront-controller但是当我运行它并尝试清除购物车时,它重定向到 url 并显示错误“不幸的是,出了点问题。 "

在日志中我发现以下错误

request.CRITICAL:未捕获的 PHP 异常 Shopware\Core\Framework\Routing\Exception\InvalidRouteScopeException:“路由 frontend.checkout.clearCart 的路由范围无效。” 在 /var/www/html/shopware6/vendor/shopware/platform/src/Core/Framework/Routing/RouteScopeListener.php 第 93 行 {"exception":"[object] (Shopware\Core\Framework\Routing\Exception\InvalidRouteScopeException (代码:0):路由frontend.checkout.clearCart的路由范围无效。位于/var/www/html/shopware6/vendor/shopware/platform/src/Core/Framework/Routing/RouteScopeListener.php:93)“} [ ]

但是,这在安装程序设置中工作正常。

标签: shopware

解决方案


您需要向控制器添加路由范围。从几周前开始这是强制性的,但似乎示例并未根据此更改。

https://docs.shopware.com/en/shopware-platform-dev-en/getting-started/recent-updates#routescope-details

将 routescope-annotation 添加到控制器就足够了: https ://github.com/shopware/swag-docs-storefront-controller/blob/master/src/Storefront/Controller/ClearCartController.php#L23

只需将其添加到注释中:

 * @RouteScope(scopes={"storefront"})

并添加路由范围:

use Shopware\Core\Framework\Routing\Annotation\RouteScope;

我将准备一个可以修复它的拉取请求。


推荐阅读