1

After having made a working "Hello World" module, I tried to make my first magento 2 real module. The goal is to add a new product type. Using several tutorials, I did :

Mine\Custproducttype\etc\module.xml

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Mine_Custproducttype" schema_version="2.0.0">
        <sequence>
            <module name="Magento_Catalog"/>
        </sequence>
    </module>
</config>

Mine\Custproducttype\etc\product_types.xml

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Catalog:etc/product_types.xsd">
    <type name="pcbproto" label="PCB Prototype" modelInstance="Mine\Custproducttype\Model\Product\Type\Pcbproto" indexPriority="10" sortOrder="25">
        <customAttributes>
            <attribute name="refundable" value="true"/>
            <attribute name="taxable" value="true"/>
        </customAttributes>
    </type>
    <composableTypes>
        <type name="pcbproto" />
    </composableTypes>
</config>

Mine\Custproducttype\Model\Product\Type\Pcbproto.php

<?php

namespace Mine\Custproducttype\Model\Product\Type;

class Pcbproto extends \Magento\Catalog\Model\Product\Type\AbstractType
{
    /**
     * Product type code
     */
    const TYPE_CODE = 'pcbproto';

    /**
     * Delete data specific for Simple product type
     *
     * @param \Magento\Catalog\Model\Product $product
     * @return void
     */
    public function deleteTypeSpecificData(\Magento\Catalog\Model\Product $product)
    {
    }
}

Mine\Custproducttype\registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Mine_Custproducttype',
    __DIR__
);

When I add my module to the magento2 app/code directory all magento commands stop working (ex : php bin/magento module:status) and give an error :

There are no commands defined in the "module" namespace.

Removing the module and is starts working again.

Thank you for your help,

2
  • Can you create composer.json file for your extension and then try. Oct 27, 2016 at 10:06
  • what is the composer.json for?
    – Alexglvr
    Oct 28, 2016 at 7:41

1 Answer 1

0

schema_version is not valid in a module.xml file anymore.

I don't remember in which version it happened but it has been replaced with setup_version

So you need to replace the following in your module.xml :

<module name="Mine_Custproducttype" schema_version="2.0.0">

With:

<module name="Mine_Custproducttype" setup_version="2.0.0">

Then you can run:

php -f bin/magento module:enable --clear-static-content Mine_Custproducttype
php -f bin/magento setup:upgrade
3
  • I was asked to recompile magento2. I then did it. All pages are blank now...I then disable the module. blank pages. Recompile magento again : the same. delete the module files, recompile, flush cash : still the same...
    – Alexglvr
    Oct 28, 2016 at 7:55
  • 1
    It was due to owner / rights problems... www-data / 777 works
    – Alexglvr
    Oct 28, 2016 at 8:13
  • @Alexglvr sweet yeah permissions are causing problems very often, glad you worked it out. Oct 28, 2016 at 8:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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