Cookies setting

Cookies help us enhance your experience on our site by storing information about your preferences and interactions. You can customize your cookie settings by choosing which cookies to allow. Please note that disabling certain cookies might impact the functionality and features of our services, such as personalized content and suggestions. Cookie Policy

Cookie Policy
Essential cookies

These cookies are strictly necessary for the site to work and may not be disabled.

Information
Always enabled
Advertising cookies

Advertising cookies deliver ads relevant to your interests, limit ad frequency, and measure ad effectiveness.

Information
Analytics cookies

Analytics cookies collect information and report website usage statistics without personally identifying individual visitors to Google.

Information
mageplaza.com

How to Create a New Product Type in Magento 2

Vinh Jacker | 12-18-2024

Create a New Product Type

Creating a new product type Magento 2 is the achievable operation when you are running Magento 2 platform. As the default, there are five types of the products you can set: Simple Product, Configurable Product, Bundle Product, Virtual Product and Downloadable Product. However, in some cases, you maybe not satisfied with the available types as well as your products are not suitable for those default product types. That is the reason why this tutorial is written by Mageplaza to help you add the new product as you need. Please follow all steps one by one.

4 Steps to create a new product type in Magento 2

Step 1: Generate the registration file

  • Setup the app\code\Mageplaza\HelloWorld\registration.php file
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Mageplaza_HelloWorld',
    __DIR__
);
  • Generate the app\code\Mageplaza\HelloWorld\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="Mageplaza_HelloWorld" setup_version="1.0.0">
 
    </module>
</config>
  • Next, the creation of the etc/product_types.xml file is necessary to determine 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="new_product_type" label="New Product Type" modelInstance="Mageplaza\HelloWorld\Model\Product\Type\NewProductType" indexPriority="60" sortOrder="80" isQty="true">
        <priceModel instance="Mageplaza\HelloWorld\Model\Product\Price" />
    </type>
</config>

Specifically,

  • Name: the name you need to set for the new product type
  • Label: the label which is visible in the Magento backend
  • Model instance: endorse the product type’s attributes
  • Price Model: endorse the charge of the new product type

Step 2: Add the code NewProductType model

  • Enter the code below: Mageplaza\HelloWorld\Model\Product\Type\NewProductType model, that should be based on Magento\Catalog\Model\Product\Type\AbstractType.
<?php
 
namespace Mageplaza\HelloWorld\Model\Product\Type;
 
class NewProductType extends \Magento\Catalog\Model\Product\Type\AbstractType {
 
 
 
}
  • After that, it is possible to rewrite some functions and implement some changes you want there.

Step 3: Add the Price model

  • Enter Mageplaza\HelloWorld\Model\Product\Price model, which should be based on the Magento\Catalog\Model\Product\Type\Price.
<?php
 namespace Mageplaza\HelloWorld\Model\Product;
 class Price extends \Magento\Catalog\Model\Product\Type\Price
 {
 
     
 }
  • Besides, you can also set the new product type as versatile type with some custom functions after extending the Magento\Catalog\Model\Product\Type\Price class

Step 4: Publish the new Magento 2 Product type

This is the step allowing you to check the result in the Magento 2 Administrator when completing the above steps. The New Product type will display as the old types (Simple or Configurable Product).

Final words

That’s all about creating new product type in Magento 2. All the steps are pretty easy to follow, so I hope it is helpful for you. If you have any question about this tutorial, feel free to add a comment. Thanks for reading!

x
    Jacker

    With over a decade of experience crafting innovative tech solutions for ecommerce businesses built on Magento, Jacker is the mastermind behind our secure and well-functioned extensions. With his expertise in building user-friendly interfaces and robust back-end systems, Mageplaza was able to deliver exceptional Magento solutions and services for over 122K+ customers around the world.



    Related Post

    Website Support
    & Maintenance Services

    Make sure your store is not only in good shape but also thriving with a professional team yet at an affordable price.

    Get Started
    mageplaza services