重定向到控制器抛出 "Unfortunately, something went wrong."

Redirect to controller throws "Unfortunately, something went wrong."

我已经在开发模板中安装了这个插件 https://github.com/shopware/swag-docs-storefront-controller 但是当我 运行 这个并试图清除购物车时它重定向到 url 并显示错误 "Unfortunately, something went wrong."

我在日志中发现以下错误

request.CRITICAL: Uncaught PHP Exception Shopware\Core\Framework\Routing\Exception\InvalidRouteScopeException: "Invalid route scope for route frontend.checkout.clearCart." at /var/www/html/shopware6/vendor/shopware/platform/src/Core/Framework/Routing/RouteScopeListener.php line 93 {"exception":"[object] (Shopware\Core\Framework\Routing\Exception\InvalidRouteScopeException(code: 0): Invalid route scope for route frontend.checkout.clearCart. at /var/www/html/shopware6/vendor/shopware/platform/src/Core/Framework/Routing/RouteScopeListener.php:93)"} []

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

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

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;

我会准备一个 pull-request 来修复它。