Akénéo service pim_catalog.saver.product is private and can’t be used in my bundle’s Controller

According to the docs, https://docs.akeneo.com/4.0/manipulate_pim_data/product/save.html, I should be able to call $saver = $this->get('pim_catalog.saver.product'); in my bundle’s controller, like this:

<?php
namespace XXXController;

use SymfonyBundleFrameworkBundleControllerController;
use SymfonyComponentHttpFoundationResponse;

class ExportController extends Controller
{
    public function exportProduct($id): Response
    {
        $saver = $this->get('pim_catalog.saver.product');
        $saver->save($id);

    
        return new Response(
            '<html><body>foo</body></html>'
        );
    }

}

However I get this error:

[2020-11-05 13:44:58] request.CRITICAL: Uncaught PHP Exception SymfonyComponentDependencyInjectionExceptionServiceNotFoundException: "The "pim_catalog.saver.product" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead." at /var/www/html/pim/vendor/symfony/dependency-injection/Container.php line 275 {"exception":"[object] (SymfonyComponentDependencyInjectionExceptionServiceNotFoundException(code: 0): The "pim_catalog.saver.product" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead. at /var/www/html/pim/vendor/symfony/dependency-injection/Container.php:275)"} []

So I would want to override the declaration of this service by adding a services.YML file into my bundle’s configuration directory (mybundle/Resources/config/services.YML) :

services:
  pim_catalog.saver.product:
    public: true
    priority: 999

However it still doesn’t work.

According to the documentation of Symfony 4, I should create an Extension class maybe. It should have the same name than Akénéo’s one, but I don’t find the latter.

What should I do?

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *