{"id":500,"date":"2023-02-11T01:13:20","date_gmt":"2023-02-10T18:13:20","guid":{"rendered":"https:\/\/magerubik.com\/blog\/?p=500"},"modified":"2023-04-24T09:25:23","modified_gmt":"2023-04-24T02:25:23","slug":"how-to-create-new-product-type-in-magento-2","status":"publish","type":"post","link":"https:\/\/magerubik.com\/blog\/how-to-create-new-product-type-in-magento-2\/","title":{"rendered":"How to create product type in Magento 2"},"content":{"rendered":"\n<div class=\"magerubik-quote\">\n\t<p>In Magento has 6 types of products available including simple, grouped, configurable, virtual, bundled and downloadable. It also supports creating new attributes and then adding them to products, which almost meets the needs of creating products with an e-commerce site. However it may be because your actual requirement needs to create a product type with behaviors and attributes that are not available from default magento. That&#8217;s why we learn how to create new product type in Magento.<\/p>\n<\/div>\n<div class=\"mr-headnote\">\n\t<p>In this article, we will assume building a gift product type in the Magerubik_GiftCard module. It is assumed that you have done building the basic structure <a href=\"https:\/\/magerubik.com\/blog\/create-magento-2-extension-step-by-step\" title=\"create magento 2 extension step by step\">declaring the module<\/a>.<\/p>\n<\/div>\n<h2 class=\"h3\"><strong>1. Declare new product type<\/strong><\/h2>\n<p>Create the <span class=\"code\">app\/code\/Aureatelabs\/NewProductType\/etc\/product_types.xml<\/span> file then put content same below:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?xml version=\"1.0\"?>\n&lt;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"..\/..\/..\/Magento\/Catalog\/etc\/product_types.xsd\">\n    &lt;type name=\"mrgiftcard\" label=\"Gift Card\" modelInstance=\"Magerubik\\GiftCard\\Model\\Product\\Type\\GiftCard\" composite=\"false\" indexPriority=\"45\" sortOrder=\"70\" isQty=\"true\">\n        &lt;priceModel instance=\"Magerubik\\GiftCard\\Model\\Product\\Price\"\/>\n\t\t&lt;customAttributes>\n           &lt;attribute name=\"refundable\" value=\"true\"\/>\n       &lt;\/customAttributes>\n    &lt;\/type>\n&lt;\/config><\/pre>\n\n\n\n<ul class=\"hkk-list\">\n\t<li>In there<\/li>\n\t<li>\u2013 <span class=\"code\">\u201cname\u201d<\/span>: new product type code<\/li>\n\t<li>\u2013 <span class=\"code\">\u201clabel\u201d<\/span>: new product type name<\/li>\n\t<li>\u2013 <span class=\"code\">\u201cmodelInstance\u201d<\/span>: new product type model<\/li>\n\t<li>\u2013 <span class=\"code\">\u201ccomposite\u201d<\/span>: allow being children of composite product types<\/li>\n\t<li>\u2013 <span class=\"code\">\u201cindexPriority\u201d<\/span>: priority index<\/li>\n\t<li>\u2013 <span class=\"code\">\u201cisQty\u201d<\/span>: whether it has a quantity<\/li>\n\t<li>\u2013 <span class=\"code\">\u201csortOrder\u201d<\/span>: position number in the sort list<\/li>\n\t<li>The customAttributes nodes can be used when Magento wants to get a list of product types that comply with the condition.<\/li>\n<\/ul>\n<p>you can also refer to other properties in the file <span class=\"code\">\/vendor\/magento\/module-catalog\/etc\/product_types.xsd<\/span><\/p>\n<p>In addition, you can also override the models: priceModel, indexerModel, stockIndexerModel. <\/p>\n<h2 class=\"h3\"><strong>2. Create Product Type Model<\/strong><\/h2>\n<p>Each product type will have a corresponding model, which is the place to modify behavior and attribute. So, you can apply your custom logic in the product type model.<\/p>\n<p>For simplicity you can choose to extend from the product type defalut then override the functions. in this case, I was choose extend from <span class=\"code\">AbstractType<\/span><\/p>\n<p>Create the <span class=\"code\">Magerubik\\GiftCard\\Model\\Product\\Type\\GiftCard.php<\/span> file then put content same below:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\nnamespace Magerubik\\GiftCard\\Model\\Product\\Type;\nuse Exception;\nuse Magento\\Catalog\\Api\\ProductRepositoryInterface;\nuse Magento\\Catalog\\Model\\Product;\nuse Magento\\Catalog\\Model\\Product\\Option;\nuse Magento\\Catalog\\Model\\Product\\Type;\nuse Magento\\Catalog\\Model\\Product\\Type\\AbstractType;\nuse Magento\\Eav\\Model\\Config;\nuse Magento\\Framework\\App\\Filesystem\\DirectoryList;\nuse Magento\\Framework\\App\\Request\\Http;\nuse Magento\\Framework\\DataObject;\nuse Magento\\Framework\\Event\\ManagerInterface;\nuse Magento\\Framework\\Exception\\LocalizedException;\nuse Magento\\Framework\\Filesystem;\nuse Magento\\Framework\\Model\\AbstractModel;\nuse Magento\\Framework\\Phrase;\nuse Magento\\Framework\\Registry;\nuse Magento\\MediaStorage\\Helper\\File\\Storage\\Database;\nuse Magerubik\\GiftCard\\Helper\\Product as DataHelper;\nuse Magerubik\\GiftCard\\Model\\Source\\FieldRenderer;\nuse Psr\\Log\\LoggerInterface;\nuse Zend_Serializer_Exception;\nclass GiftCard extends AbstractType\n{\n    const TYPE_GIFTCARD = 'mrgiftcard';\n    protected $_dataHelper;\n    protected $request;\n    protected $logger;\n    public function __construct(\n        Option $catalogProductOption,\n        Config $eavConfig,\n        Type $catalogProductType,\n        ManagerInterface $eventManager,\n        Database $fileStorageDb,\n        Filesystem $filesystem,\n        Registry $coreRegistry,\n        LoggerInterface $logger,\n        ProductRepositoryInterface $productRepository,\n        DataHelper $dataHelper,\n        Http $request,\n    ) {\n        $this->request = $request;\n        $this->_dataHelper = $dataHelper;\n        $this->logger = $logger;\n        parent::__construct(\n            $catalogProductOption,\n            $eavConfig,\n            $catalogProductType,\n            $eventManager,\n            $fileStorageDb,\n            $filesystem,\n            $coreRegistry,\n            $logger,\n            $productRepository\n        );\n    }\n    \/**\n     * Sets flag that product has required options, because gift card always\n     * has some required options, at least - recipient name\n     * @param Product $product\n     * @return $this\n     *\/\n    public function beforeSave($product)\n    {\n        parent::beforeSave($product);\n        $product->setTypeHasOptions(true);\n        $product->setTypeHasRequiredOptions(true);\n        return $this;\n    }\n    \/**\n     * Check if Gift Card product is available for sale\n     * @param Product|AbstractModel $product\n     * @return bool\n     *\/\n    public function isSalable($product)\n    {\n        $product = $product->load($product->getId());\n        if (!count($product->getGiftCardAmounts())) {\n            return false;\n        }\n        return parent::isSalable($product);\n    }\n    \/**\n     * @param DataObject $buyRequest\n     * @param Product $product\n     * @param string $processMode\n     * @return array|Phrase|string\n     *\/\n    protected function _prepareProduct(DataObject $buyRequest, $product, $processMode)\n    {\n        $result = parent::_prepareProduct($buyRequest, $product, $processMode);\n        if (is_string($result)) {\n            return $result;\n        }\n        try {\n            return $this->prepareGiftCardData($buyRequest, $product->load($product->getId()));\n        } catch (LocalizedException $e) {\n            return $e->getMessage();\n        } catch (Exception $e) {\n            $this->logger->critical($e);\n            return __('Something went wrong.');\n        }\n    }\n    \/**\n     * @param DataObject $buyRequest\n     * @param Product $product\n     * @return array\n     * @throws LocalizedException\n     *\/\n    protected function prepareGiftCardData($buyRequest, $product)\n    {\n        $redirectUrl = $this->request->getServer('REDIRECT_URL');\n        if (strpos($redirectUrl, 'wishlist\/index\/add\/') !== false) {\n            return [$product];\n        }\n        $amount = $this->_validateAmount($buyRequest, $product);\n        $product->addCustomOption(FieldRenderer::AMOUNT, $amount, $product);\n        if ($sender = $buyRequest->getFrom()) {\n            $product->addCustomOption(FieldRenderer::SENDER, ucfirst($sender), $product);\n        }\n        if ($recipient = $buyRequest->getTo()) {\n            $product->addCustomOption(FieldRenderer::RECIPIENT, ucfirst($recipient), $product);\n        }\n        if ($message = $buyRequest->getMessage()) {\n            $product->addCustomOption(FieldRenderer::MESSAGE, $message, $product);\n        }\n        return [$product];\n    }\n    \/**\n     * @param DataObject $buyRequest\n     * @param Product $product\n     * @return float\n     * @throws LocalizedException\n     *\/\n    protected function _validateAmount($buyRequest, $product)\n    {\n        $amount = $buyRequest->getAmount();\n        $currentAction = $this->request->getFullActionName();\n        $allowAmounts = [];\n        $attribute = $product->getResource()->getAttribute('gift_card_amounts');\n        if ($attribute) {\n            $attribute->getBackend()->afterLoad($product);\n            $allowAmounts = $product->getGiftCardAmounts();\n        }\n        $allowAmountValues = array_column($allowAmounts, 'amount');\n        if ($currentAction !== 'wishlist_index_add' &amp;&amp; (!count($allowAmounts) || !in_array($amount, $allowAmountValues, true))) {\n\t\t\tthrow new LocalizedException(\n\t\t\t\t__('Please choose your amount again. The allowed amount must be one of these values: %1', implode(',', $allowAmountValues) )\n                );\n       }\n        return $amount;\n    }\n    \/**\n     * Check if product can be bought\n     * @param Product $product\n     * @return $this\n     * @throws LocalizedException\n     * @throws Zend_Serializer_Exception\n     *\/\n    public function checkProductBuyState($product)\n    {\n        parent::checkProductBuyState($product);\n        $option = $product->getCustomOption('info_buyRequest');\n        if ($option instanceof \\Magento\\Quote\\Model\\Quote\\Item\\Option) {\n            $buyRequest = new DataObject($this->_dataHelper->unserialize($option->getValue()));\n            $this->prepareGiftCardData($buyRequest, $product);\n        }\n        return $this;\n    }\n    \/**\n     * @param Product $product\n     * @param DataObject $buyReques\n     * @return array\n     *\/\n    public function processBuyRequest($product, $buyRequest)\n    {\n        $delivery = (int)$buyRequest->getDelivery();\n        $options = [\n            'amount' => $buyRequest->getAmount(),\n            'from' => $buyRequest->getFrom(),\n            'to' => $buyRequest->getTo(),\n            'message' => $buyRequest->getMessage(),\n            'delivery_date' => $buyRequest->getDeliveryDate(),\n        ];\n        return $options;\n    }\n    \/**\n     * Delete data specific for Gift Card product type\n     * @param Product $product\n     * @return void\n     *\/\n    public function deleteTypeSpecificData(Product $product)\n    {\n    }\n}<\/pre>\n\n\n\n<p>By overriding the methods in the model you can control the behavior of the product as you like without having to use observers or plugins.Some examples of such methods: beforeSave(), save(), isSalable(), _prepareProduct(), isVirtual()<\/p>\n<p>After the product type is declared in the XML and the corresponding product type model is created, you can see new product type in the admin.<\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/cdn2.magerubik.com\/media\/extensions\/magento-2-product-type-option.jpg\" alt=\"magento 2 product type option\" class=\"wp-image-80\"><\/figure>\t\n<h2 class=\"h3\"><strong>3. Create Install data file<\/strong><\/h2>\n<p>In this file will to create attributes associated with the new product type.<\/p>\n<p>Create the <span class=\"code\">Magerubik\\GiftCard\\Setup\\InstallData.php<\/span> file then put content same below:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\nnamespace Magerubik\\GiftCard\\Setup;\nuse Exception;\nuse Magento\\Catalog\\Model\\Category;\nuse Magento\\Catalog\\Model\\Product;\nuse Magento\\Catalog\\Model\\Product\\Attribute\\Backend\\Boolean;\nuse Magento\\Catalog\\Model\\Product\\Attribute\\Backend\\Price;\nuse Magento\\Catalog\\Model\\Product\\AttributeSet\\Options;\nuse Magento\\Catalog\\Setup\\CategorySetup;\nuse Magento\\Catalog\\Setup\\CategorySetupFactory;\nuse Magento\\Eav\\Model\\Entity\\Attribute\\ScopedAttributeInterface;\nuse Magento\\Eav\\Setup\\EavSetupFactory;\nuse Magento\\Framework\\Setup\\InstallDataInterface;\nuse Magento\\Framework\\Setup\\ModuleContextInterface;\nuse Magento\\Framework\\Setup\\ModuleDataSetupInterface;\nuse Magerubik\\GiftCard\\Model\\Attribute\\Backend\\Amount;\nuse Magerubik\\GiftCard\\Model\\Attribute\\Backend\\MultiSelect;\nuse Magerubik\\GiftCard\\Model\\Attribute\\Backend\\Pattern;\nuse Magerubik\\GiftCard\\Model\\GiftCard\\Template;\nuse Magerubik\\GiftCard\\Model\\Product\\DeliveryMethods;\nuse Magerubik\\GiftCard\\Model\\Product\\Type\\GiftCard;\nclass InstallData implements InstallDataInterface\n{\n    protected $eavSetupFactory;\n    protected $categorySetupFactory;\n    protected $templateFactory;\n    protected $_attributeSet;\n    public function __construct(\n        EavSetupFactory $eavSetupFactory,\n        CategorySetupFactory $categorySetupFactory,\n        Options $attributeSet\n    ) {\n        $this->eavSetupFactory = $eavSetupFactory;\n        $this->categorySetupFactory = $categorySetupFactory;\n        $this->_attributeSet = $attributeSet;\n    }\n    public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)\n    {\n        $installer = $setup;\n        $catalogSetup = $this->categorySetupFactory->create(['setup' => $setup]);\n        $installer->startSetup();\n        $entityTypeId = $catalogSetup->getEntityTypeId(Category::ENTITY);\n        foreach ($this->_attributeSet->toOptionArray() as $set) {\n            $catalogSetup->addAttributeGroup($entityTypeId, $set['value'], 'Gift Card Information', 10);\n        }\n        $catalogSetup->addAttribute(Product::ENTITY, 'gift_code_pattern', array_merge($this->getDefaultOptions(), [\n            'label' => 'Gift Code Pattern',\n            'type' => 'varchar',\n            'input' => 'text',\n            'backend' => Pattern::class,\n            'input_renderer' => \\Magerubik\\GiftCard\\Block\\Adminhtml\\Product\\Helper\\Form\\Config\\Pattern::class,\n            'required' => true,\n            'sort_order' => 10\n        ]));\n        $catalogSetup->addAttribute(Product::ENTITY, 'gift_card_amounts', array_merge($this->getDefaultOptions(), [\n            'label' => 'Gift Card Amounts',\n            'type' => 'varchar',\n            'input' => 'text',\n            'backend' => Amount::class,\n            'global' => ScopedAttributeInterface::SCOPE_WEBSITE,\n            'sort_order' => 20\n        ]));\n\t\t$this->addRemoveApply($catalogSetup);\n        $installer->endSetup();\n    }\n\tprotected function addRemoveApply($catalogSetup)\n    {\n        $fieldAdd = ['weight'];\n        foreach ($fieldAdd as $field) {\n            $applyTo = $catalogSetup->getAttribute('catalog_product', $field, 'apply_to');\n            if ($applyTo) {\n                $applyTo = explode(',', $applyTo);\n                if (!in_array(GiftCard::TYPE_GIFTCARD, $applyTo, true)) {\n                    $applyTo[] = GiftCard::TYPE_GIFTCARD;\n                    $catalogSetup->updateAttribute('catalog_product', 'weight', 'apply_to', implode(',', $applyTo));\n                }\n            }\n        }\n\n        $fieldRemove = ['cost'];\n        foreach ($fieldRemove as $field) {\n            $applyTo = explode(',', $catalogSetup->getAttribute('catalog_product', $field, 'apply_to'));\n            if (in_array('mrgiftcard', $applyTo, true)) {\n                foreach ($applyTo as $k => $v) {\n                    if ($v === 'mrgiftcard') {\n                        unset($applyTo[$k]);\n                        break;\n                    }\n                }\n                $catalogSetup->updateAttribute('catalog_product', $field, 'apply_to', implode(',', $applyTo));\n            }\n        }\n\n        return $this;\n    }\n    protected function getDefaultOptions()\n    {\n        return [\n            'group' => 'Gift Card Information',\n            'backend' => '',\n            'frontend' => '',\n            'class' => '',\n            'source' => '',\n            'global' => ScopedAttributeInterface::SCOPE_STORE,\n            'visible' => true,\n            'required' => false,\n            'user_defined' => true,\n            'default' => '',\n            'searchable' => false,\n            'filterable' => false,\n            'comparable' => false,\n            'visible_on_front' => false,\n            'unique' => false,\n            'apply_to' => GiftCard::TYPE_GIFTCARD,\n            'used_in_product_listing' => true\n        ];\n    }\n}<\/pre>\n\n\n\n<h2 class=\"h3\"><strong>3. Create Price Model<\/strong><\/h2>\n<p>This file allows extending classes to interact with nearly every aspect of price calculation.<\/p>\n<p>Create the <span class=\"code\">Magerubik\\GiftCard\\Setup\\InstallData.php<\/span> file then put content same below:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\nnamespace Magerubik\\GiftCard\\Model\\Product;\nuse Magento\\Catalog\\Model\\Product;\nuse Magento\\Catalog\\Model\\Product\\Type\\Price as CatalogPrice;\nclass Price extends CatalogPrice\n{\n    public function getFinalPrice($qty, $product)\n    {\n        if ($qty === null &amp;&amp; $product->getCalculatedFinalPrice() !== null) {\n            return $product->getCalculatedFinalPrice();\n        }\n        $finalPrice = $this->getPrice($product);\n        if ($product->hasCustomOptions()) {\n            $amount = $product->getCustomOption('amount');\n            $amount = (float)($amount ? $amount->getValue() : 0);\n            $attribute = $product->getResource()->getAttribute('gift_card_amounts');\n            $attribute->getBackend()->afterLoad($product);\n            $allowAmounts = $product->load($product->getId())->getGiftCardAmounts();\n            foreach ($allowAmounts as $amountValue) {\n\t\t\t\tif ((float)$amountValue['amount'] === $amount) {\n\t\t\t\t\t$finalPrice = $amountValue['price'];\n\t\t\t\t\tbreak;\n\t\t\t\t}\n            }\n        }\n        $product->setFinalPrice($finalPrice);\n        $this->_eventManager->dispatch('catalog_product_get_final_price', ['product' => $product, 'qty' => $qty]);\n        $finalPrice = $product->getData('final_price');\n        $finalPrice = $this->_applyOptionsPrice($product, $qty, $finalPrice);\n        $finalPrice = max(0, $finalPrice);\n        $product->setFinalPrice($finalPrice);\n        return $finalPrice;\n    }\n}<\/pre>\n\n\n\n<blockquote class=\"wp-block-quote\">\n\t<p>To finish creating a product type you need to add behaviors for the product when adding to cart and after checkout. In addition, you also have to build the frontend, backend, email&#8230; and we will cover those issues in another article. In the next posts we will learn how to <a href=\"https:\/\/magerubik.com\/blog\/create-category-attribute-in-magento-2\" title=\"Create Category Attribute in Magento 2\">create category attribute in Magento 2<\/a>. <a href=\"https:\/\/magerubik.com\/contact\" title=\"Contact Magerubik\">Contact us<\/a> if you face any problems during the installation process.<\/p>\n<\/blockquote>\n<p class=\"simple-note\">You can download the demo code for this entire series from <a href=\"https:\/\/github.com\/magerubik\/module-simple\" title=\"demo code on github\" rel=\"nofollow noopener\">GitHub<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Magento has 6 types of products available including simple, grouped, configurable, virtual, bundled and downloadable. It also supports creating<\/p>\n","protected":false},"author":1,"featured_media":501,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-500","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-magento-2-extension-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to create product type in Magento 2 | MageRubik<\/title>\n<meta name=\"description\" content=\"Magento has provided us with a solution to build a fully functional e-commerce website. but sometimes we still want to renovate it a bit\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/magerubik.com\/blog\/how-to-create-new-product-type-in-magento-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to create product type in Magento 2 | MageRubik\" \/>\n<meta property=\"og:description\" content=\"Magento has provided us with a solution to build a fully functional e-commerce website. but sometimes we still want to renovate it a bit\" \/>\n<meta property=\"og:url\" content=\"https:\/\/magerubik.com\/blog\/how-to-create-new-product-type-in-magento-2\/\" \/>\n<meta property=\"og:site_name\" content=\"MageRubik\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/magerubik\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/magerubik\" \/>\n<meta property=\"article:published_time\" content=\"2023-02-10T18:13:20+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-04-24T02:25:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/magerubik.com\/blog\/wp-content\/uploads\/2023\/02\/magento-how-to-create-new-product-type.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"800\" \/>\n\t<meta property=\"og:image:height\" content=\"445\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Hilary howard\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/www.twitter.com\/magerubik\" \/>\n<meta name=\"twitter:site\" content=\"@magerubik\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Hilary howard\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/magerubik.com\/blog\/how-to-create-new-product-type-in-magento-2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/magerubik.com\/blog\/how-to-create-new-product-type-in-magento-2\/\"},\"author\":{\"name\":\"Hilary howard\",\"@id\":\"https:\/\/magerubik.com\/blog\/#\/schema\/person\/dad797dc557c925c92436706db1359d8\"},\"headline\":\"How to create product type in Magento 2\",\"datePublished\":\"2023-02-10T18:13:20+00:00\",\"dateModified\":\"2023-04-24T02:25:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/magerubik.com\/blog\/how-to-create-new-product-type-in-magento-2\/\"},\"wordCount\":495,\"publisher\":{\"@id\":\"https:\/\/magerubik.com\/blog\/#\/schema\/person\/dad797dc557c925c92436706db1359d8\"},\"image\":{\"@id\":\"https:\/\/magerubik.com\/blog\/how-to-create-new-product-type-in-magento-2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/magerubik.com\/blog\/wp-content\/uploads\/2023\/02\/magento-how-to-create-new-product-type.jpg\",\"articleSection\":[\"Magento 2 Extension Tutorials\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/magerubik.com\/blog\/how-to-create-new-product-type-in-magento-2\/\",\"url\":\"https:\/\/magerubik.com\/blog\/how-to-create-new-product-type-in-magento-2\/\",\"name\":\"How to create product type in Magento 2 | MageRubik\",\"isPartOf\":{\"@id\":\"https:\/\/magerubik.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/magerubik.com\/blog\/how-to-create-new-product-type-in-magento-2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/magerubik.com\/blog\/how-to-create-new-product-type-in-magento-2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/magerubik.com\/blog\/wp-content\/uploads\/2023\/02\/magento-how-to-create-new-product-type.jpg\",\"datePublished\":\"2023-02-10T18:13:20+00:00\",\"dateModified\":\"2023-04-24T02:25:23+00:00\",\"description\":\"Magento has provided us with a solution to build a fully functional e-commerce website. but sometimes we still want to renovate it a bit\",\"breadcrumb\":{\"@id\":\"https:\/\/magerubik.com\/blog\/how-to-create-new-product-type-in-magento-2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/magerubik.com\/blog\/how-to-create-new-product-type-in-magento-2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/magerubik.com\/blog\/how-to-create-new-product-type-in-magento-2\/#primaryimage\",\"url\":\"https:\/\/magerubik.com\/blog\/wp-content\/uploads\/2023\/02\/magento-how-to-create-new-product-type.jpg\",\"contentUrl\":\"https:\/\/magerubik.com\/blog\/wp-content\/uploads\/2023\/02\/magento-how-to-create-new-product-type.jpg\",\"width\":800,\"height\":445,\"caption\":\"Mageno how to create new product type\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/magerubik.com\/blog\/how-to-create-new-product-type-in-magento-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Magerubik blog site\",\"item\":\"https:\/\/magerubik.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to create product type in Magento 2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/magerubik.com\/blog\/#website\",\"url\":\"https:\/\/magerubik.com\/blog\/\",\"name\":\"Magerubik\",\"description\":\"MageRubik blog site\",\"publisher\":{\"@id\":\"https:\/\/magerubik.com\/blog\/#\/schema\/person\/dad797dc557c925c92436706db1359d8\"},\"alternateName\":\"Magento 2 Extension\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/magerubik.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/magerubik.com\/blog\/#\/schema\/person\/dad797dc557c925c92436706db1359d8\",\"name\":\"Hilary howard\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/magerubik.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/magerubik.com\/blog\/wp-content\/uploads\/2022\/03\/magerubik-logo.png\",\"contentUrl\":\"https:\/\/magerubik.com\/blog\/wp-content\/uploads\/2022\/03\/magerubik-logo.png\",\"width\":265,\"height\":90,\"caption\":\"Hilary howard\"},\"logo\":{\"@id\":\"https:\/\/magerubik.com\/blog\/#\/schema\/person\/image\/\"},\"sameAs\":[\"http:\/\/localhost\/blog\",\"https:\/\/www.facebook.com\/magerubik\",\"https:\/\/www.instagram.com\/magerubik\",\"https:\/\/www.linkedin.com\/magerubik\",\"https:\/\/www.pinterest.com\/magerubik\",\"https:\/\/twitter.com\/https:\/\/www.twitter.com\/magerubik\",\"https:\/\/www.myspace.com\/magerubik\",\"https:\/\/www.youtube.com\/magerubik\",\"https:\/\/www.soundcloud.com\/magerubik\",\"https:\/\/www.tumblr.com\/magerubik\",\"https:\/\/www.wikipedia.com\/magerubik\"],\"url\":\"https:\/\/magerubik.com\/blog\/author\/hilary-howard\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to create product type in Magento 2 | MageRubik","description":"Magento has provided us with a solution to build a fully functional e-commerce website. but sometimes we still want to renovate it a bit","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/magerubik.com\/blog\/how-to-create-new-product-type-in-magento-2\/","og_locale":"en_US","og_type":"article","og_title":"How to create product type in Magento 2 | MageRubik","og_description":"Magento has provided us with a solution to build a fully functional e-commerce website. but sometimes we still want to renovate it a bit","og_url":"https:\/\/magerubik.com\/blog\/how-to-create-new-product-type-in-magento-2\/","og_site_name":"MageRubik","article_publisher":"https:\/\/www.facebook.com\/magerubik","article_author":"https:\/\/www.facebook.com\/magerubik","article_published_time":"2023-02-10T18:13:20+00:00","article_modified_time":"2023-04-24T02:25:23+00:00","og_image":[{"width":800,"height":445,"url":"https:\/\/magerubik.com\/blog\/wp-content\/uploads\/2023\/02\/magento-how-to-create-new-product-type.jpg","type":"image\/jpeg"}],"author":"Hilary howard","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/www.twitter.com\/magerubik","twitter_site":"@magerubik","twitter_misc":{"Written by":"Hilary howard","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/magerubik.com\/blog\/how-to-create-new-product-type-in-magento-2\/#article","isPartOf":{"@id":"https:\/\/magerubik.com\/blog\/how-to-create-new-product-type-in-magento-2\/"},"author":{"name":"Hilary howard","@id":"https:\/\/magerubik.com\/blog\/#\/schema\/person\/dad797dc557c925c92436706db1359d8"},"headline":"How to create product type in Magento 2","datePublished":"2023-02-10T18:13:20+00:00","dateModified":"2023-04-24T02:25:23+00:00","mainEntityOfPage":{"@id":"https:\/\/magerubik.com\/blog\/how-to-create-new-product-type-in-magento-2\/"},"wordCount":495,"publisher":{"@id":"https:\/\/magerubik.com\/blog\/#\/schema\/person\/dad797dc557c925c92436706db1359d8"},"image":{"@id":"https:\/\/magerubik.com\/blog\/how-to-create-new-product-type-in-magento-2\/#primaryimage"},"thumbnailUrl":"https:\/\/magerubik.com\/blog\/wp-content\/uploads\/2023\/02\/magento-how-to-create-new-product-type.jpg","articleSection":["Magento 2 Extension Tutorials"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/magerubik.com\/blog\/how-to-create-new-product-type-in-magento-2\/","url":"https:\/\/magerubik.com\/blog\/how-to-create-new-product-type-in-magento-2\/","name":"How to create product type in Magento 2 | MageRubik","isPartOf":{"@id":"https:\/\/magerubik.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/magerubik.com\/blog\/how-to-create-new-product-type-in-magento-2\/#primaryimage"},"image":{"@id":"https:\/\/magerubik.com\/blog\/how-to-create-new-product-type-in-magento-2\/#primaryimage"},"thumbnailUrl":"https:\/\/magerubik.com\/blog\/wp-content\/uploads\/2023\/02\/magento-how-to-create-new-product-type.jpg","datePublished":"2023-02-10T18:13:20+00:00","dateModified":"2023-04-24T02:25:23+00:00","description":"Magento has provided us with a solution to build a fully functional e-commerce website. but sometimes we still want to renovate it a bit","breadcrumb":{"@id":"https:\/\/magerubik.com\/blog\/how-to-create-new-product-type-in-magento-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/magerubik.com\/blog\/how-to-create-new-product-type-in-magento-2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/magerubik.com\/blog\/how-to-create-new-product-type-in-magento-2\/#primaryimage","url":"https:\/\/magerubik.com\/blog\/wp-content\/uploads\/2023\/02\/magento-how-to-create-new-product-type.jpg","contentUrl":"https:\/\/magerubik.com\/blog\/wp-content\/uploads\/2023\/02\/magento-how-to-create-new-product-type.jpg","width":800,"height":445,"caption":"Mageno how to create new product type"},{"@type":"BreadcrumbList","@id":"https:\/\/magerubik.com\/blog\/how-to-create-new-product-type-in-magento-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Magerubik blog site","item":"https:\/\/magerubik.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to create product type in Magento 2"}]},{"@type":"WebSite","@id":"https:\/\/magerubik.com\/blog\/#website","url":"https:\/\/magerubik.com\/blog\/","name":"Magerubik","description":"MageRubik blog site","publisher":{"@id":"https:\/\/magerubik.com\/blog\/#\/schema\/person\/dad797dc557c925c92436706db1359d8"},"alternateName":"Magento 2 Extension","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/magerubik.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/magerubik.com\/blog\/#\/schema\/person\/dad797dc557c925c92436706db1359d8","name":"Hilary howard","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/magerubik.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/magerubik.com\/blog\/wp-content\/uploads\/2022\/03\/magerubik-logo.png","contentUrl":"https:\/\/magerubik.com\/blog\/wp-content\/uploads\/2022\/03\/magerubik-logo.png","width":265,"height":90,"caption":"Hilary howard"},"logo":{"@id":"https:\/\/magerubik.com\/blog\/#\/schema\/person\/image\/"},"sameAs":["http:\/\/localhost\/blog","https:\/\/www.facebook.com\/magerubik","https:\/\/www.instagram.com\/magerubik","https:\/\/www.linkedin.com\/magerubik","https:\/\/www.pinterest.com\/magerubik","https:\/\/twitter.com\/https:\/\/www.twitter.com\/magerubik","https:\/\/www.myspace.com\/magerubik","https:\/\/www.youtube.com\/magerubik","https:\/\/www.soundcloud.com\/magerubik","https:\/\/www.tumblr.com\/magerubik","https:\/\/www.wikipedia.com\/magerubik"],"url":"https:\/\/magerubik.com\/blog\/author\/hilary-howard\/"}]}},"_links":{"self":[{"href":"https:\/\/magerubik.com\/blog\/wp-json\/wp\/v2\/posts\/500","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/magerubik.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/magerubik.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/magerubik.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/magerubik.com\/blog\/wp-json\/wp\/v2\/comments?post=500"}],"version-history":[{"count":3,"href":"https:\/\/magerubik.com\/blog\/wp-json\/wp\/v2\/posts\/500\/revisions"}],"predecessor-version":[{"id":630,"href":"https:\/\/magerubik.com\/blog\/wp-json\/wp\/v2\/posts\/500\/revisions\/630"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/magerubik.com\/blog\/wp-json\/wp\/v2\/media\/501"}],"wp:attachment":[{"href":"https:\/\/magerubik.com\/blog\/wp-json\/wp\/v2\/media?parent=500"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/magerubik.com\/blog\/wp-json\/wp\/v2\/categories?post=500"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/magerubik.com\/blog\/wp-json\/wp\/v2\/tags?post=500"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}