Jump to content

[SOLVED] Custom module ClassNotFoundException on updateProduct


Recommended Posts

Hello,

I built up a module which was seeming to work quite fine on product page load, but I'm getting an error when selecting a product variant:

ClassNotFoundException

Attempted to load class "MyModule" from the global namespace.
Did you forget a "use" statement?

With the module, I'm overriding ProductControllerCore in override/controllers/front/ProductController.php like:

class ProductController extends ProductControllerCore
{
    public function initContent()
    {
        ...

        $content = MyModule::getMyModuleContent($id_lang);

        ...

        parent::initContent();
    }
}

MyModule is located in mymodule/mymodule.php like:

<?php

...

class MyModule extends Module
{
    ...
}

Again, this is working just fine until I select a product combination.

I tried to add a composer.json file like:

{
  "name" : "prestashop/mymodule",
  "description": "My Module",
  "autoload": {
    "psr-4": {
      "MyModule\\": "/",
      "MyModuleClass\\": "classes/"
    }
  },
  "type" : "prestashop-module"
}

But it did not solve my issue.

Any idea on how I could get this solved please?

 

Edited by Shapes (see edit history)
Link to comment
Share on other sites

Well, in case this can spare someone some time..

I changed composer.json to:

{
  "name" : "prestashop/mymodule",
  "description": "My Module",
  "autoload": {
    "psr-4": {
      "MyModule\\": "classes/"
    },
    "classmap": [
      "mymodule.php",
      "classes/"
    ]
  },
  "type" : "prestashop-module"
}

Then I ran composer dump-autoload in my module root folder and reinstalled module.

It seems to work fine now.

  • Like 1
Link to comment
Share on other sites

  • Shapes changed the title to [SOLVED] Custom module ClassNotFoundException on updateProduct

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