Adding a new product type in Magento 2
Create etc/product_types.xml in your module to add a new product type in Magento 2:
1 |
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../Catalog/etc/product_types.xsd"> <type name="demoproduct" label="Demo Product" modelInstance="Genmato\DemoProduct\Model\Product\Type\Demo" indexPriority="25" sortOrder="25"> <customAttributes> <attribute name="refundable" value="true"/> </customAttributes> </type> </config> |
The second step requires creating the modelInstance:
1 |
/** * @category Genmato * @package Genmato_MageStackProduct * @copyright Copyright (c) 2015 Genmato BV (https://genmato.com) */ namespace Genmato\DemoProduct\Model\Product\Type; class Demo extends \Magento\Catalog\Model\Product\Type\AbstractType { /** * Delete data specific for Simple product type * * @param \Magento\Catalog\Model\Product $product * @return void */ public function deleteTypeSpecificData(\Magento\Catalog\Model\Product $product) { } } |
More tips from Magento 2 Developer’s Cookbook