Jump to content

Decorating the PS 8.1.6 ProductController


Recommended Posts

I am trying to decorate the PS 8.1.6 ProductController and I am getting below error:

You have requested a non-existent service "PrestaShopBundle\Controller\Admin\Sell\Catalog\Product\ProductController".

This is my service.yml file
image.thumb.png.dcdbb0eff3c5af481ac33256c70e64d9.png

Could you please advise what I might be missing?
I'm happy to provide any additional information or data that might be helpful.

Link to comment
Share on other sites

Hello,

I tried with your example and it displays the same exception for me.

By looking into the documentation, it looks like this should out of the box, but it doesn't.

They highlight the PrestaShopBundle\Controller\Admin\Improve\Design\CmsPageController in there, which works as expected if you try to decorate it. The main difference between these classes seems to be the fact that the Product one has a constructor.

This is one way you can achieve what you want:

1. In your services.yml, define the product service as well as follows:
 

PrestaShopBundle\Controller\Admin\Sell\Catalog\Product\ProductController:
    autowire: true


    
2. Now you should be able to decorate the PrestaShopBundle\Controller\Admin\Sell\Catalog\Product\ProductController service. In your decorator please add autowire: true as well, in order to avoid another exception.

3. As stated in the documentation, you will need to run bin/console cache:clear in order for your decorator to override the routes exposed by the default controller.

Let me know if the above helps.

  • Thanks 1
Link to comment
Share on other sites

1 hour ago, Andrei H said:

Hello,

I tried with your example and it displays the same exception for me.

By looking into the documentation, it looks like this should out of the box, but it doesn't.

They highlight the PrestaShopBundle\Controller\Admin\Improve\Design\CmsPageController in there, which works as expected if you try to decorate it. The main difference between these classes seems to be the fact that the Product one has a constructor.

This is one way you can achieve what you want:

1. In your services.yml, define the product service as well as follows:
 

PrestaShopBundle\Controller\Admin\Sell\Catalog\Product\ProductController:
    autowire: true


    
2. Now you should be able to decorate the PrestaShopBundle\Controller\Admin\Sell\Catalog\Product\ProductController service. In your decorator please add autowire: true as well, in order to avoid another exception.

3. As stated in the documentation, you will need to run bin/console cache:clear in order for your decorator to override the routes exposed by the default controller.

Let me know if the above helps.

Many many tanks, it worked.

  • Like 1
Link to comment
Share on other sites

Need help again :)
I don't know why I am facing so much difficulties to decorating the new PS8.X productController and there documentation doesn't help at all.
Now I am getting this error:

Quote

The controller for URI "/sell/catalog/products-v2/" is not callable: Controller "PrestaShopBundle\Controller\Admin\Sell\Catalog\Product\ProductController" cannot be fetched from the container because it is private. Did you forget to tag the service with "controller.service_arguments"?

I have tried to follow the symfony's examples by adding these tags prestashop.core.controllers, controller.service_arguments, container.service_subscriber, which I could see are in original controller but it didn't helped.

services:
    
    PrestaShopBundle\Controller\Admin\Sell\Catalog\Product\ProductController:
        autowire: true

    custom_product_controller:
        autowire: true
        class: mymodule\Controller\Admin\customProductController
        decorates: PrestaShopBundle\Controller\Admin\Sell\Catalog\Product\ProductController        
        arguments: ["@custom_product_controller.inner"]
        tags: ['controller.service_arguments']

Do you or anybody else knows what I have to do add/remove to make it work.
Thanks in advance
                   

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...