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
<?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
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) { } }
Create catalog_product_view_type_generic.xml file at view/frontend/layout/ folder
<?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.
Note: When users are creating custom product types, they might encounter issues in the admin panel, such as the product save button not working make sure you fix all such issues.
Thank You!