Tips & Tutorials

How to create a new product type in Magento 2

As you know, Magento supports several product types, each type has different behavior and logic. As the default, there are six types of the products you can set: Simple Product, Grouped ProductConfigurable Product, Bundle Product, Virtual Product, and Downloadable Product.


But in some cases, default Magento product type cannot be enough for your business. So depends on your situation, you can create a new Magento 2 product type with the following tutorial.




1. Config XML


The first step is defining a custom product type with an XML declaration. Specifically, in the <Vendor>/<Module>/etc/product_types.xml, add an XML snippet of the following form to declare the new product type’s critical information.



There are three required attributes.


– name: Custom product attribute code used in code and database.


– label: Defines the product type label in Magento admin.


– modelInstance: Custom product type model specifies custom business logic.


2. Product Type Model


A product model must inherit from the \Magento\Catalog\Model\Product\Type\AbstractType base class. You can override any method for custom logic code.


Method: deleteTypeSpecificData is an abstract method, this method can be used to delete data specific for the product type.



Some common methods you can override are:


– isVirtual: Check is virtual product.


– isSaleable: Check is product available for sale.


– getWeight: Default action to get weight of product.


– hasOptions: Return true of product has options.


– hasRequiredOptions: Check if product has required options.

After all of the above steps, when you check the Add new product dropdown, here is what you should see:



3. Price Model


You can specify a price model in product type Config XML.



The price model referenced should extend \Magento\Catalog\Model\Product\Type\Price. This class has no abstract methods which must be implemented but allows extending classes to interact with nearly every aspect of price calculation.


Add attributes for the new product type.


Some product attribute only applies for a few default Magento product types, so you need to add your new product type into them.


Add this function to this file UpgradeData.php in your module:

This function will add your new attribute code to these product attributes : ‘cost’, ‘price’,  ‘special_price’, ‘special_from_date’, ‘special_to_date’, ‘weight’, ‘tax_class_id’.




4. Core Product Types


You can extend one of the core product types instead of the abstract directly.


The following product type classes are available natively in the core.


Simple: \Magento\Catalog\Model\Product\Type\Simple


Virtual: \Magento\Catalog\Model\Product\Type\Virtual


Configurable: \Magento\ConfigurableProduct\Model\Product\Type\Configurable


Grouped: \Magento\GroupedProduct\Model\Product\Type\Grouped


Downloadable: \Magento\Downloadable\Model\Product\Type


Bundle: \Magento\Bundle\Model\Product\Type


Giftcard (Enterprise Edition Only): \Magento\GiftCard\Model\Catalog\Product\Type\Giftcard


5. Bottom line


Magento 2 provides a framework for creating custom product types. This is very helpful for merchants who want to create custom logic based on different products and services that they are selling.


How to create a new product type in Magento 2
Rate this post

A  passionate copywriter.

Marketing Executive | Content Manager

Author: Rosie Phan

Rosie Phan

A  passionate copywriter. Marketing Executive | Content Manager

Related Posts

Leave a comment

Your email address will not be published. Required fields are marked *

ten − two =

At Magenest, we help our customers thrive by offering advanced solutions and working with excellent business partners.

We’re proud to be one of the top Magento 2 developers with capability in building integration solutions with third party business systems and applications.


Please follow & like us