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 product types. That is the reason why this tutorial is written by Mageplaza to aid you add the new product as you need. Please follow all steps one by one.
Mageplaza\HelloWorld\Model\Product\Type\NewProductType
modelMageplaza\HelloWorld\Model\Product\Price model
app\code\Mageplaza\HelloWorld\registration.php
fileapp\code\Mageplaza\HelloWorld\registration.php
file<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Mageplaza_HelloWorld',
__DIR__
);
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>
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,
Mageplaza\HelloWorld\Model\Product\Type\NewProductType
modelMageplaza\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 {
}
Mageplaza\HelloWorld\Model\Product\Price
modelMageplaza\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
{
}
Magento\Catalog\Model\Product\Type\Price
classThis 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).
Please leave comments if you have any questions, feedbacks.