How to Create Custom Product Type in Magento 2
Magento 2 supports 6 product types by default: Simple Product, Grouped Product Configurable Product, Bundle Product, Virtual Product, and Downloadable Product. These product types, each having its own features, enables Magento 2 to support a wide range of industries.
However, owing to diverse Magento areas, the need may arise to create custom product type in Magento 2 to satisfy the requirements of the store to implement specific features.
Magento 2 allows customization to create your own complete new Magento 2 product type! Isn’t it a powerful feature for the developer? ?
No worries now when a client comes with weird requirements that the default product types can’t fulfill because now you are going to learn the easy method to create custom product type in Magento 2. Yaay! ?
Method to Create Custom Product Type In Magento 2:
- create a product_types.xml file in etc folder
1234567891011<?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="generic" label="Generic Product" modelInstance="Vendor\Extension\Model\Product\Type\Generic" indexPriority="100" sortOrder="10"><customAttributes><attribute name="refundable" value="true"/></customAttributes></type><composableTypes><type name="generic" /></composableTypes></config> - create Generic.php at Model/Product/Type/ directory
12345678910namespace Vendor\Extension\Model\Product\Type;use Magento\Catalog\Model\Product;use Magento\Catalog\Model\Product\Type\AbstractType;class Generic extends AbstractType{const TYPE_CODE = 'generic';public function deleteTypeSpecificData(Product $product){}} - create catalog_product_view_type_generic.xml file at view/frontend/layout/ folder
1234<?xml version="1.0"?><page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"><body/></page>
With the above method, you no longer need to turn down the client with limited product types! You can always create one for yourself ?
Get started today! If you face any doubts midway, I’m here to help you out. Just post your doubts in the Comments section below.?
Reward the post with 5 stars if it helped you create your custom product type! ?
Thank You!
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
Prev
Add Magento 2 Attribute Values Before Add to Cart Button in Product Page
How to Get Logged in Customer Data in Magento 2
Next