Hello Magento Folks,
Welcome again in the Magento Tutorial series where we are going to learn How to Create a New Product Type in Magento 2 with appropriate codes for it. Learn step by step solution How to Configure Color Swatches in Magento 2 in our most recent published article which will help you in improving your customer experience for your store.
Introduction:
Mainly, there are 6 types of products supported in Magento 2 namely Simple product, Grouped product, Bundle product, Configurable product, virtual product, and Downloadable product. But every time everyone is not satisfied with these products so there is also a feature of creating a new Magento 2 product type. So, for creating your required product type follow the given below steps which will help you thoroughly. Let’s Create It.
Steps to Create a New Product Type in Magento 2.
Step 1: Generate registration.php file
Setup the app\code\Magecomp\Customproducttype\registration.php file
<?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Magecomp_Customproducttype', __DIR__ );
Generate the app\code\Magecomp\Customproducttype\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="Magecomp_Customproducttype" setup_version="1.0.0"/> </config>
Creating of etc/product_types.xml file is mandatory to identify the model of the new product type
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Catalog:etc/product_types.xsd"> <type name="custom_product_type" label="Custom Product Type" modelInstance="Magecomp\Customproducttype\Model\Product\Type\Customproducttype" indexPriority="60" sortOrder="90" isQty="true"> <priceModel instance="Magecomp\Customproducttype\Model\Product\Price" /> </type> </config>
Name: Name for the new product type.
Label: Label which is displayed in the Magento Backend.
Model instance: To support the product type’s attributes
Price Model: To support the charge of the new product type.
Step 2: Now, you have to add the code NewProductType model
Magecomp\Customproducttype\Model\Product\Type\Customproducttype model, that should be based on Magento\Catalog\Model\Product\Type\AbstractType.
<?php namespace Magecomp\Customproducttype\Model\Product\Type; class Customproducttype extends \Magento\Catalog\Model\Product\Type\AbstractType { }
After completing this, you can rewrite some functions and implement some changes.
Step 3: Add the Price model
Enter Magecomp\Customproducttype\Model\Product\Price model, which should be based on the Magento\Catalog\Model\Product\Type\Price. <?php namespace Magecomp\Customproducttype\Model\Product; class Price extends \Magento\Catalog\Model\Product\Type\Price { }
Besides, you can also set the new product type as a multipurpose type with some custom functions after extending the Magento\Catalog\Model\Product\Type\Price class
Step 4: Publish the new Magento 2 Product type
After you publish the new product type you will be completing the creation of product type in Magento 2 and can use it wherever you need. The new published type will also be displayed like the other product types.
Final Words:
Therefore, the above steps will help you in successfully creating the configurable product type in your Magento 2 store.
I hope the explanation was helpful for you and for any queries you face in implementing the above steps feel free to contact MageComp support which will help you. Also, comment down your reviews in the comment section below and also share with your Magento friends and help them in achieving this.
Happy Reading?