General

How to Create a New Product Type in Magento 2

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?

Click to rate this post!
[Total: 5 Average: 3.4]
Gaurav Jain

Gaurav Jain is Co-Founder and Adobe Certified Expert-Magento Commerce Business Practitioner. Being Computer Engineer?‍? and possessing Extensive Marketing skills he handles all kinds of customer Queries and his Happy? & Helping? Nature makes customer's day Delightful. When he isn’t working, you’ll find Gaurav Reading on Books? or Traveling?. Also, he is Speaker at Magento Meetups.

Recent Posts

How to Add Tooltip in Checkout Shipping Field in Magento 2?

Hello Magento Friends, In today’s blog, I will explain How to Add Tooltip in Checkout…

2 days ago

How to Integrate and Use MongoDB with Laravel?

MongoDB is a popular NoSQL database that offers flexibility and scalability when handling modern web…

4 days ago

NodeJS | Callback Function

In NodeJS, callbacks empower developers to execute asynchronous operations like reading files, handling requests, and…

4 days ago

How to Show SKU in Order Summary in Magento 2?

Hello Magento Friends, In today’s blog, we will learn How to Show SKU in Order…

6 days ago

Best Colors to Use for CTA Buttons

The "Buy Now" and "Add to Cart" buttons serve as the primary call-to-action (CTA) elements…

1 week ago

Magento 2: How to Save Custom Field Value to quote_address for Multi-Shipping Orders

Hello Magento Friends, In Magento 2, the checkout process allows customers to choose multiple shipping…

1 week ago