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:
1.create a product_types.xml file in etc folder
1 2 3 4 5 6 7 8 9 10 11 |
<?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> |
2.create Generic.php at Model/Product/Type/ directory
1 2 3 4 5 6 7 8 9 10 11 |
<?xml version="1.0"?> namespace 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) { } } |
3.create catalog_product_view_type_generic.xml file at view/frontend/layout/ folder
1 2 3 4 |
<?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!