Search code examples
shopware

Shopware 6 : detail: "\"CustomTest\\Controller\\BackendController\" has no container set, did you forget to define it as a service subscriber?"


Trying to add some controller into the Shopware 6 administration but facing a 500 error while investigating into the console.

BackendController extending to the Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

file: BackendController.php has a below-route scope.


/**
     * @RouteScope(scopes={"api"})
     * @Route("/api/_action/customtest/test", name="api.action.customtest.testConnection", methods={"GET"})
     *
     * @param Request $request
     * @param Context $context
     *
     * @return JsonResponse
     */
    public function getUserConnectionStatus(Request $request, Context $context): JsonResponse
    {
         
            $response = [
                'success' => true,
                'connected' => false,
                'link' => ''
                )
            ];        

        return new JsonResponse($response);
    }

file: connection-service-estatus.js


getConnectionSettingsStatus() {
        const apiRoute = `/_action/${this.getApiBasePath()}/test`;       
        return this.httpClient.get(
            apiRoute,
            {
                headers: this.getBasicHeaders()
            }
        ).then((response) => {
            return ApiService.handleResponse(response);
        });
    }

Solution

  • When you register your controller in src/Resources/config/services.xml you have to call the method setContainer. See Shopware documentation. For example:

    <service id="YourNamespace\BackendController" public="true">
        <call method="setContainer">
            <argument type="service" id="service_container"/>
        </call>
    </service>