Jump to content

[PS1.7.8.6] Class not found when decorate a controller


Recommended Posts

Hi,

I'm writing a module in order to add a "comment" field in the stock movements.

I don't know if it's a good approach but first I want to see if I can override the Stock Movements listing.

After some research, I decided to decorate the PrestaShopBundle\Controller\Api\StockMovementController.

Si my config/services.yml is

services:
  custom_controller:
    class: MyCompany\ProductExtras\Controller\Admin\StockMvtController
    decorates: PrestaShopBundle\Controller\Api\StockMovementController
    arguments: ['@custom_controller.inner']
    public: true

 

And my file StockMvtController.php is 

<?php

namespace MyCompany\ProductExtras\Controller\Admin;

use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController;
use PrestaShopBundle\Controller\Api\StockMovementController;
use Symfony\Component\HttpFoundation\Request;

class StockMvtController extends StockMovementController
{
    /**
     * @var StockMovementController
     */
    private $decoratedController;

    public function __construct(StockMovementController $decoratedController)
    {
        $this->decoratedController = $decoratedController;
    }

    public function listMovementsAction(Request $request)
    {
        return $this->decoratedController->listMovementsAction($request);
    }
}

 

But when I want to display the movements list, I have the error 500 with 

Attempted to load class "StockMvtController" from namespace "MyCompany\ProductExtras\Controller\Admin".
Did you forget a "use" statement for another namespace?

I don't know were the problem is. it seems to bu in the var/cache/dev/ContainerX4krxiu/getCustomControllerService.php file but even if I set a use on my controller I have the same error.

Link to comment
Share on other sites

Ok so I Finally find a solution...

The error was in my composer.json

I had 

"autoload": {
    "psr-4": {
      "myCompany\\ProductExtras\\": "src/"
    },

Instead of

"autoload": {
    "psr-4": {
      "myCompany\\ProductExtras\\": "src/",
      "myCompany\\ProductExtras\\Controller\\": "Controller/"
    },

 

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...