17

I tried to create new module in vendor directory in Magento Enterprise 2.0.0. The module could not be loaded after I ran the Magento setup:upgrade.

If I move my files to the app/code directory, the module will be set up successfully.

For Magento 2 Enterprise edition, all modules are in vendor directory but Community edition uses app/code directory. I wonder if it is possible to create custom module in the vendor directory. If yes, what are the differences between creating a custom module in app/code and vendor.

vendor/Test/Testing/registration.php

<?php

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Test_Testing',
    __DIR__ );

vendor/Test/Testing/composer.json

{   "name": "test/testing",   "description": "Testing",   "require": {
    "php": "~5.5.0|~5.6.0|~7.0.0",
    "magento/framework": "100.0.*"   },   "type": "magento2-module",   "version": "0.1.0",   "license": [
    "proprietary"   ],   "autoload": {
    "files": [ "registration.php" ],
    "psr-4": {
      "Test\\Testing\\": ""
    }   } }

vendor/Test/Testing/etc/module.xml

<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Test_Testing" setup_version="0.1.0">
    </module> </config>
  • Are you sure that you need to keep Enterprise modules in vendor directory ? – Valery Statichnyi Dec 12 '15 at 14:46
  • Sorry, I does not understand what you mean because I downloaded the Magento 2 Enterprise package and all modules were stored in the vendor directory no matter it is core module or Enterprise module. Even Magento framework is stored in vendor directory. No app/code directory existed in the original package. – Jason Yip Dec 12 '15 at 16:58
  • Might I ask what the "psr-4" item in your composer.json does? We use packaging but we have our own GitLab so we have to code in vendor as well, however my code isn't recognized. I can instantiate my class from Magento core modules but Cron does not work. I think it has to do with autoloading, my files aren't being read. I have a class Company\Reviews\Cron\Check in file /vendor/company/Reviews/Cron/Check.php and I have a cronjob like Company\Reviews\Cron\Check but in database cron_schedule it just says "Class Company\Reviews\Cron\Check does not exist" – Jacco Amersfoort Mar 8 '17 at 16:15
11

Custom modules should not be developed in vendor directory. Copy content from vendor/magento/magento2-base to the root of the project, create custom .gitignore as described here and initialize new git repository. Then develop custom module under app/code/VendorName/ModuleName.

Later, when you decide to distribute the module, it will have to be packaged and published. When someone will buy/install your module, it will be automatically installed by composer to vendor directory of their project.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.