-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't load custom extension class #772
Comments
The error message proves that magento tries to load your class, but it can't find it. So System config works correctly and problem is with class path. Did you try running composer install? |
I tried re-running composer install in the root. But no help. Do you need to preload custom extensions somehow? Or define your models somewhere? It definitely worked in an earlier version of Magento2, I can't see what changed. /app/code/Inchoo/Stripe/Model/Source/Cctype.php
|
It does work if I move the module to the app/code/Mage location, rename everything and call
It's as if custom extension classes can't be found. |
@morningtime , you're right in your investigation. |
@morningtime we are working on a fix that will require no code changes on your part. A solution in the meantime, and also for a little performance gain, you can add your module to composer.json's autoload section. In your example, you would go to composer.json -> autoload -> psr-4, and add "Inchoo" : "app/code/Inchoo/" According to the composer format: EDIT: It is recommended to add this information to the composer.json file when using 3rd party modules. |
I think an ideal solution is to adapt your extension to Magento 2 + Composer. If your package had a composer.json file with proper autoload section, there would be no need for workaround. But in order for such a package to be recognized by Magento 2 installer and properly moved to app/code directory, it needs to define type "magento2-module". See examples at http://packages.magento.com/#!/magento/module- |
Ok, if add the line to the root composer.json, it works:
But when I try a composer.json file in the app/code/Inchoo/Stripe/composer.json location, it doesn't work. Here's what I tried:
|
With the Composer approach, it works in different way. You don't have the source code in app/code in the first place. Instead, you would declare in your root composer.json in "require" section something like this:
Then if you run But it takes a lot of work to do -- this extension needs to be properly packaged and registered on a packaging server (for example, packagist.org) |
@morningtime , please, use solution with root |
Thank you very much. I think we need some way to add third party extensions flexibly. |
To repair the old-school include_path based autoloading approach, corresponding section could be added to
It is a deprecated feature of a Composer which is not going to be removed though.
Instead of this modules' source code could reside in
Not really, you can simply load package from a git repository.
There could be more than one way to add extension, so would be nice to have some appropriate workflow described covering a couple of use cases:
|
Well I'm confused. How are commercial extension going to be added, that won't have a public composer package? How can magento 2.x users create some custom code easily, without creating a github account and a composer package? In Magento 1.x you could put some code in app/code/local to create custom extensions. I find it a bit cumbersome to put all custom/commercial code in the /vendor location with "some configuration files" under app/code. Sounds possibly confusing. What's the point of app/code if it can only host 'Mage' extensions, not community and local contributions? The include_path seems most practical fix, but this will be deprecated...? In Magento 1.x you could also upload extension "packages" via the /downloader system. How will this work then in Magento 2.x? |
If you put PSR-0 compliant code in
which is equivalent to having the following in the root composer.json file: "psr-0": {
"": ["app/code/", "var/generation/"]
} |
Thank you for the clue, @otoolec! We are now closing this ticket as resolved. The code with the fix must be available in the repository. |
Thanks so much. |
Is there any updates on this issue ? |
@keyurshah070 please avoid posting on closed issues. Start a new one. |
MSI: 532: Adapt AdaptAssignStatusToProductPlugin to complex products
It appears that you can no longer load customer extension classes from XML files, like this:
Error is:
Class Inchoo\Stripe\Model\Source\Cctype does not exist
For example, In a custom extension, etc/adminhtml/system.xml there are a few lines like this:
(File exists, in /app/code/Inchoo/Stripe/Model/Source/Cctype.php, namespace and class name are OK)
See
https://github.com/ivanweiler/Inchoo_Stripe
It used to work in an earlier Magento2 build... what changed?
The text was updated successfully, but these errors were encountered: