How to Create a New Product Type in Magento 2

In Magento 2, there are available the following product types:

  • \Magento\Catalog\Model\Product\Type\Simple;
  • \Magento\ConfigurableProduct\Model\Product\Type\Configurable;
  • \Magento\GroupedProduct\Model\Product\Type\Grouped;
  • \Magento\Catalog\Model\Product\Type\Virtual;
  • \Magento\Bundle\Model\Product\Type;
  • \Magento\Downloadable\Model\Product\Type;
  • \Magento\GiftCard\Model\Catalog\Product\Type\Giftcard.

Also, we can add custom product type in the following next steps:

Create new module

Create a new module (how to do this,  find in the previous article How to Create Module in Magento 2), for example, MageDirect_Test.

Create product_types.xml

Create product_types.xml file with the next content:

This file has next attributes:

  • the required name attribute is the unique name of custom product type, that will be used in code and database;
  • the optional label attribute – label for admin area;
  • the optional modelInstance attribute defines product type model.

See more attributes in module-catalog/etc/product_types.xsd file.

Create model class

Create a model class and paste next content:

As we can see, this class should inherit from the Magento\Catalog\Model\Product\Type\AbstractType base class and override deleteTypeSpecificData method.

Associate core attributes

Associate core attributes with the new product type in an install data script:

Enable new module

Check the result

Check the result in admin Catalog > Products:

Also, take a look at the official documentation:

Don’t be afraid to ask a Magento consulting in case you need it, we are always ready to help you.

Was this article helpful?
Dislike 0
Views: 391
Lilya Gogoleva

Lilya GogolevaMagento Developer

Rate us
Please wait...