Sylius: No MetadataInterface service found for customized ProductController

Created on 18 Oct 2017  路  5Comments  路  Source: Sylius/Sylius

| Q | A
| ---------------- | -----
| Bug report? |yes
| Feature request? | no
| BC Break report? | no
| RFC? | no
| Sylius version | 1.1.0

Following the documentation (http://docs.sylius.org/en/latest/customization/controller.html) the following error occurs when creating a custom ProductController

"Cannot autowire service "AppBundleController\ProductController": argument "$metadata" of method "Sylius\Bundle\ResourceBundleController\ResourceController::__construct()" references interface "SyliusComponent\Resource\Metadata\MetadataInterface" but no such service exists."

The code:

_AppBundleController\ProductController.php:_

namespace AppBundle\Controller;

use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
use Symfony\Component\HttpFoundation\Request;

class ProductController extends ResourceController
{
    public function seoAction(Request $request)
    {
    }
}

_app/config/config.yml_

sylius_product:
    resources:
        product:
            classes:
                controller: AppBundle\Controller\ProductController`

_app/config/routing.yml_

app_shop_product_seo:
    path: /products/{slug}/seo
    methods: [GET]
    defaults:
        _controller: sylius.controller.product:seoAction
        _sylius:
            repository:
                method: findOneByChannelAndSlug
                arguments:
                    - "expr:service('sylius.context.channel').getChannel()"
                    - "expr:service('sylius.context.locale').getLocaleCode()"
                    - $slug`

Most helpful comment

I just disabled autowiring for my controller in app/config/services.yml :

# add more services, or override services that need manual wiring
    # AppBundle\Service\ExampleService:
    #     arguments:
    #         $someArgument: 'some_value'

    AppBundle\Controller\RecipeController:
        autowire: false

All 5 comments

This issue seems to be fixed by disabling autowire for the ProductController class in the services configuration.

I have the save problem. @matthijsch And, it does not work when disabling autowire. How do you fix it?

same problem here, any solution?

I have solved it by disabling autowiring this way in case someone else has this problem.

 services: 
   _instanceof:
        Sylius\Bundle\ResourceBundle\Controller\ResourceController:
            autowire: false

I just disabled autowiring for my controller in app/config/services.yml :

# add more services, or override services that need manual wiring
    # AppBundle\Service\ExampleService:
    #     arguments:
    #         $someArgument: 'some_value'

    AppBundle\Controller\RecipeController:
        autowire: false
Was this page helpful?
0 / 5 - 0 ratings