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

Five Essential Payroll Compliance Tips for eCommerce Startups

Are you setting up a payroll system for your eCommerce startup? Ensuring compliance with myriad…

1 hour ago

Optimizing Laravel Blade: Unlocking Advanced Fetcher Techniques

In the expansive universe of Laravel development, Blade serves as the stellar templating engine, propelling…

3 hours ago

Magento 2: Add Quantity Increment and Decrement on Category Page

Hello Magento Friends, In this blog, we will discuss about adding quantity increment and decrement…

2 days ago

How to Integrate ChatGPT with Laravel Application?

In this guide, we'll explore how to integrate ChatGPT, an AI-powered chatbot, with a Laravel…

5 days ago

What are Net Sales? How to Calculate Your Net Sales?

In the world of business, understanding financial metrics is crucial for making informed decisions and…

1 week ago

Magento 2 Extensions Digest April 2024 (New Release & Updates)

Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…

1 week ago