How to create a new product type in magento2












2















I have created new product type in magento2 using https://www.classyllama.com/blog/custom-product-types-magento-2.



After the i can't see any product info in view page.. It only display the Images tab in view page..



enter image description here



product_type.xml



<?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="custom_product_type_code" label="Custom Product Type Label" modelInstance="XXXCustomiseProductInfoModelProductType" indexPriority="60" sortOrder="80" isQty="true">
</type>
</config>


Type.php



class Type extends MagentoCatalogModelProductTypeAbstractType
{
const TYPE_ID = 'custom_product_type_code';

/**
* {@inheritdoc}
*/
public function deleteTypeSpecificData(MagentoCatalogModelProduct $product)
{
// method intentionally empty
}
}









share|improve this question

























  • Can you see any error in exception.log ?

    – Supravat M
    Dec 18 '18 at 5:14











  • main.CRITICAL: Cannot gather stats! Warning!stat(): stat failed for /var/www/html/XXX/pub/static/adminhtml/Magento/backend/en_US/mage/requirejs/mixins.js {"exception":"[object] (Magento\Framework\Exception\FileSystemException(code: 0): Cannot gather stats! Warning!stat(): stat failed for /var/www/html/xxx/pub/static/adminhtml/Magento/backend/en_US/mage/requirejs/mixins.js at /var/www/html/xxx/vendor/magento/framework/Filesystem/Driver/File.php:71)"}

    – Mano M
    Dec 18 '18 at 5:16











  • In console...ReferenceError: Unable to process binding "if: function(){return label }" Message: label is not defined

    – Mano M
    Dec 18 '18 at 5:16











  • @ManoM can you please update your question with product_types.xml and other files which you have created.

    – Ramkishan Suthar
    Dec 18 '18 at 5:21













  • updated my post..

    – Mano M
    Dec 18 '18 at 5:24
















2















I have created new product type in magento2 using https://www.classyllama.com/blog/custom-product-types-magento-2.



After the i can't see any product info in view page.. It only display the Images tab in view page..



enter image description here



product_type.xml



<?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="custom_product_type_code" label="Custom Product Type Label" modelInstance="XXXCustomiseProductInfoModelProductType" indexPriority="60" sortOrder="80" isQty="true">
</type>
</config>


Type.php



class Type extends MagentoCatalogModelProductTypeAbstractType
{
const TYPE_ID = 'custom_product_type_code';

/**
* {@inheritdoc}
*/
public function deleteTypeSpecificData(MagentoCatalogModelProduct $product)
{
// method intentionally empty
}
}









share|improve this question

























  • Can you see any error in exception.log ?

    – Supravat M
    Dec 18 '18 at 5:14











  • main.CRITICAL: Cannot gather stats! Warning!stat(): stat failed for /var/www/html/XXX/pub/static/adminhtml/Magento/backend/en_US/mage/requirejs/mixins.js {"exception":"[object] (Magento\Framework\Exception\FileSystemException(code: 0): Cannot gather stats! Warning!stat(): stat failed for /var/www/html/xxx/pub/static/adminhtml/Magento/backend/en_US/mage/requirejs/mixins.js at /var/www/html/xxx/vendor/magento/framework/Filesystem/Driver/File.php:71)"}

    – Mano M
    Dec 18 '18 at 5:16











  • In console...ReferenceError: Unable to process binding "if: function(){return label }" Message: label is not defined

    – Mano M
    Dec 18 '18 at 5:16











  • @ManoM can you please update your question with product_types.xml and other files which you have created.

    – Ramkishan Suthar
    Dec 18 '18 at 5:21













  • updated my post..

    – Mano M
    Dec 18 '18 at 5:24














2












2








2


1






I have created new product type in magento2 using https://www.classyllama.com/blog/custom-product-types-magento-2.



After the i can't see any product info in view page.. It only display the Images tab in view page..



enter image description here



product_type.xml



<?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="custom_product_type_code" label="Custom Product Type Label" modelInstance="XXXCustomiseProductInfoModelProductType" indexPriority="60" sortOrder="80" isQty="true">
</type>
</config>


Type.php



class Type extends MagentoCatalogModelProductTypeAbstractType
{
const TYPE_ID = 'custom_product_type_code';

/**
* {@inheritdoc}
*/
public function deleteTypeSpecificData(MagentoCatalogModelProduct $product)
{
// method intentionally empty
}
}









share|improve this question
















I have created new product type in magento2 using https://www.classyllama.com/blog/custom-product-types-magento-2.



After the i can't see any product info in view page.. It only display the Images tab in view page..



enter image description here



product_type.xml



<?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="custom_product_type_code" label="Custom Product Type Label" modelInstance="XXXCustomiseProductInfoModelProductType" indexPriority="60" sortOrder="80" isQty="true">
</type>
</config>


Type.php



class Type extends MagentoCatalogModelProductTypeAbstractType
{
const TYPE_ID = 'custom_product_type_code';

/**
* {@inheritdoc}
*/
public function deleteTypeSpecificData(MagentoCatalogModelProduct $product)
{
// method intentionally empty
}
}






magento2.2 php-7






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 18 '18 at 5:24







Mano M

















asked Dec 18 '18 at 5:10









Mano MMano M

866218




866218













  • Can you see any error in exception.log ?

    – Supravat M
    Dec 18 '18 at 5:14











  • main.CRITICAL: Cannot gather stats! Warning!stat(): stat failed for /var/www/html/XXX/pub/static/adminhtml/Magento/backend/en_US/mage/requirejs/mixins.js {"exception":"[object] (Magento\Framework\Exception\FileSystemException(code: 0): Cannot gather stats! Warning!stat(): stat failed for /var/www/html/xxx/pub/static/adminhtml/Magento/backend/en_US/mage/requirejs/mixins.js at /var/www/html/xxx/vendor/magento/framework/Filesystem/Driver/File.php:71)"}

    – Mano M
    Dec 18 '18 at 5:16











  • In console...ReferenceError: Unable to process binding "if: function(){return label }" Message: label is not defined

    – Mano M
    Dec 18 '18 at 5:16











  • @ManoM can you please update your question with product_types.xml and other files which you have created.

    – Ramkishan Suthar
    Dec 18 '18 at 5:21













  • updated my post..

    – Mano M
    Dec 18 '18 at 5:24



















  • Can you see any error in exception.log ?

    – Supravat M
    Dec 18 '18 at 5:14











  • main.CRITICAL: Cannot gather stats! Warning!stat(): stat failed for /var/www/html/XXX/pub/static/adminhtml/Magento/backend/en_US/mage/requirejs/mixins.js {"exception":"[object] (Magento\Framework\Exception\FileSystemException(code: 0): Cannot gather stats! Warning!stat(): stat failed for /var/www/html/xxx/pub/static/adminhtml/Magento/backend/en_US/mage/requirejs/mixins.js at /var/www/html/xxx/vendor/magento/framework/Filesystem/Driver/File.php:71)"}

    – Mano M
    Dec 18 '18 at 5:16











  • In console...ReferenceError: Unable to process binding "if: function(){return label }" Message: label is not defined

    – Mano M
    Dec 18 '18 at 5:16











  • @ManoM can you please update your question with product_types.xml and other files which you have created.

    – Ramkishan Suthar
    Dec 18 '18 at 5:21













  • updated my post..

    – Mano M
    Dec 18 '18 at 5:24

















Can you see any error in exception.log ?

– Supravat M
Dec 18 '18 at 5:14





Can you see any error in exception.log ?

– Supravat M
Dec 18 '18 at 5:14













main.CRITICAL: Cannot gather stats! Warning!stat(): stat failed for /var/www/html/XXX/pub/static/adminhtml/Magento/backend/en_US/mage/requirejs/mixins.js {"exception":"[object] (Magento\Framework\Exception\FileSystemException(code: 0): Cannot gather stats! Warning!stat(): stat failed for /var/www/html/xxx/pub/static/adminhtml/Magento/backend/en_US/mage/requirejs/mixins.js at /var/www/html/xxx/vendor/magento/framework/Filesystem/Driver/File.php:71)"}

– Mano M
Dec 18 '18 at 5:16





main.CRITICAL: Cannot gather stats! Warning!stat(): stat failed for /var/www/html/XXX/pub/static/adminhtml/Magento/backend/en_US/mage/requirejs/mixins.js {"exception":"[object] (Magento\Framework\Exception\FileSystemException(code: 0): Cannot gather stats! Warning!stat(): stat failed for /var/www/html/xxx/pub/static/adminhtml/Magento/backend/en_US/mage/requirejs/mixins.js at /var/www/html/xxx/vendor/magento/framework/Filesystem/Driver/File.php:71)"}

– Mano M
Dec 18 '18 at 5:16













In console...ReferenceError: Unable to process binding "if: function(){return label }" Message: label is not defined

– Mano M
Dec 18 '18 at 5:16





In console...ReferenceError: Unable to process binding "if: function(){return label }" Message: label is not defined

– Mano M
Dec 18 '18 at 5:16













@ManoM can you please update your question with product_types.xml and other files which you have created.

– Ramkishan Suthar
Dec 18 '18 at 5:21







@ManoM can you please update your question with product_types.xml and other files which you have created.

– Ramkishan Suthar
Dec 18 '18 at 5:21















updated my post..

– Mano M
Dec 18 '18 at 5:24





updated my post..

– Mano M
Dec 18 '18 at 5:24










1 Answer
1






active

oldest

votes


















3














Please try below code to create custom product type.



In your etc/product_types.xml add following code



<?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 label="Customtype" modelInstance="XXXCustomiseProductInfoModelProductTypeCustomtypecode" name="customtypecode">
<priceModel instance="XXXCustomiseProductInfoModelProductPrice"/>
</type>
</config>


Create price model Model/Product/Price.php and add following code



<?php
namespace XXXCustomiseProductInfoModelProduct;

class Price extends MagentoCatalogModelProductTypePrice
{

}


In your Model/Product/Type/Customtypecode.php add following code



<?php
namespace XXXCustomiseProductInfoModelProductType;

class Customtypecode extends MagentoCatalogModelProductTypeSimple
{

const TYPE_ID = 'customtypecode';

/**
* {@inheritdoc}
*/
public function deleteTypeSpecificData(MagentoCatalogModelProduct $product)
{
// method intentionally empty
}
}


Add following code in Setup/InstallData.php



<?php    
namespace XXXCustomiseProductInfoSetup;

use MagentoFrameworkSetupInstallDataInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupModuleDataSetupInterface;
use MagentoEavSetupEavSetup;
use MagentoEavSetupEavSetupFactory;

class InstallData implements InstallDataInterface
{

private $eavSetupFactory;

/**
* Constructor
*
* @param MagentoEavSetupEavSetupFactory $eavSetupFactory
*/
public function __construct(EavSetupFactory $eavSetupFactory)
{
$this->eavSetupFactory = $eavSetupFactory;
}

/**
* {@inheritdoc}
*/
public function install(
ModuleDataSetupInterface $setup,
ModuleContextInterface $context
) {
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);

// associate these attributes with new product type
$fieldList = [
'price',
'special_price',
'special_from_date',
'special_to_date',
'minimal_price',
'cost',
'tier_price',
'weight',
];

// make these attributes applicable to new product type
foreach ($fieldList as $field) {
$applyTo = explode(
',',
$eavSetup->getAttribute(MagentoCatalogModelProduct::ENTITY, $field, 'apply_to')
);
if (!in_array(XXXCustomiseProductInfoModelProductTypeCustomtypecode::TYPE_ID, $applyTo)) {
$applyTo = XXXCustomiseProductInfoModelProductTypeCustomtypecode::TYPE_ID;
$eavSetup->updateAttribute(
MagentoCatalogModelProduct::ENTITY,
$field,
'apply_to',
implode(',', $applyTo)
);
}
}
}
}


Please try and let me know if any issue.






share|improve this answer
























  • Still not working

    – Mano M
    Dec 18 '18 at 6:09











  • are you getting any error ? in exception log or system log ?

    – Aasim Goriya
    Dec 18 '18 at 6:11













  • After clearing cache its working fine.....thanks.

    – Mano M
    Dec 18 '18 at 6:13











  • Its neccessary to add installdata and price model for new product?

    – Mano M
    Dec 18 '18 at 6:18











  • Installdata is necessary but price model is not

    – Aasim Goriya
    Dec 18 '18 at 6:21











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f254969%2fhow-to-create-a-new-product-type-in-magento2%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














Please try below code to create custom product type.



In your etc/product_types.xml add following code



<?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 label="Customtype" modelInstance="XXXCustomiseProductInfoModelProductTypeCustomtypecode" name="customtypecode">
<priceModel instance="XXXCustomiseProductInfoModelProductPrice"/>
</type>
</config>


Create price model Model/Product/Price.php and add following code



<?php
namespace XXXCustomiseProductInfoModelProduct;

class Price extends MagentoCatalogModelProductTypePrice
{

}


In your Model/Product/Type/Customtypecode.php add following code



<?php
namespace XXXCustomiseProductInfoModelProductType;

class Customtypecode extends MagentoCatalogModelProductTypeSimple
{

const TYPE_ID = 'customtypecode';

/**
* {@inheritdoc}
*/
public function deleteTypeSpecificData(MagentoCatalogModelProduct $product)
{
// method intentionally empty
}
}


Add following code in Setup/InstallData.php



<?php    
namespace XXXCustomiseProductInfoSetup;

use MagentoFrameworkSetupInstallDataInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupModuleDataSetupInterface;
use MagentoEavSetupEavSetup;
use MagentoEavSetupEavSetupFactory;

class InstallData implements InstallDataInterface
{

private $eavSetupFactory;

/**
* Constructor
*
* @param MagentoEavSetupEavSetupFactory $eavSetupFactory
*/
public function __construct(EavSetupFactory $eavSetupFactory)
{
$this->eavSetupFactory = $eavSetupFactory;
}

/**
* {@inheritdoc}
*/
public function install(
ModuleDataSetupInterface $setup,
ModuleContextInterface $context
) {
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);

// associate these attributes with new product type
$fieldList = [
'price',
'special_price',
'special_from_date',
'special_to_date',
'minimal_price',
'cost',
'tier_price',
'weight',
];

// make these attributes applicable to new product type
foreach ($fieldList as $field) {
$applyTo = explode(
',',
$eavSetup->getAttribute(MagentoCatalogModelProduct::ENTITY, $field, 'apply_to')
);
if (!in_array(XXXCustomiseProductInfoModelProductTypeCustomtypecode::TYPE_ID, $applyTo)) {
$applyTo = XXXCustomiseProductInfoModelProductTypeCustomtypecode::TYPE_ID;
$eavSetup->updateAttribute(
MagentoCatalogModelProduct::ENTITY,
$field,
'apply_to',
implode(',', $applyTo)
);
}
}
}
}


Please try and let me know if any issue.






share|improve this answer
























  • Still not working

    – Mano M
    Dec 18 '18 at 6:09











  • are you getting any error ? in exception log or system log ?

    – Aasim Goriya
    Dec 18 '18 at 6:11













  • After clearing cache its working fine.....thanks.

    – Mano M
    Dec 18 '18 at 6:13











  • Its neccessary to add installdata and price model for new product?

    – Mano M
    Dec 18 '18 at 6:18











  • Installdata is necessary but price model is not

    – Aasim Goriya
    Dec 18 '18 at 6:21
















3














Please try below code to create custom product type.



In your etc/product_types.xml add following code



<?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 label="Customtype" modelInstance="XXXCustomiseProductInfoModelProductTypeCustomtypecode" name="customtypecode">
<priceModel instance="XXXCustomiseProductInfoModelProductPrice"/>
</type>
</config>


Create price model Model/Product/Price.php and add following code



<?php
namespace XXXCustomiseProductInfoModelProduct;

class Price extends MagentoCatalogModelProductTypePrice
{

}


In your Model/Product/Type/Customtypecode.php add following code



<?php
namespace XXXCustomiseProductInfoModelProductType;

class Customtypecode extends MagentoCatalogModelProductTypeSimple
{

const TYPE_ID = 'customtypecode';

/**
* {@inheritdoc}
*/
public function deleteTypeSpecificData(MagentoCatalogModelProduct $product)
{
// method intentionally empty
}
}


Add following code in Setup/InstallData.php



<?php    
namespace XXXCustomiseProductInfoSetup;

use MagentoFrameworkSetupInstallDataInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupModuleDataSetupInterface;
use MagentoEavSetupEavSetup;
use MagentoEavSetupEavSetupFactory;

class InstallData implements InstallDataInterface
{

private $eavSetupFactory;

/**
* Constructor
*
* @param MagentoEavSetupEavSetupFactory $eavSetupFactory
*/
public function __construct(EavSetupFactory $eavSetupFactory)
{
$this->eavSetupFactory = $eavSetupFactory;
}

/**
* {@inheritdoc}
*/
public function install(
ModuleDataSetupInterface $setup,
ModuleContextInterface $context
) {
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);

// associate these attributes with new product type
$fieldList = [
'price',
'special_price',
'special_from_date',
'special_to_date',
'minimal_price',
'cost',
'tier_price',
'weight',
];

// make these attributes applicable to new product type
foreach ($fieldList as $field) {
$applyTo = explode(
',',
$eavSetup->getAttribute(MagentoCatalogModelProduct::ENTITY, $field, 'apply_to')
);
if (!in_array(XXXCustomiseProductInfoModelProductTypeCustomtypecode::TYPE_ID, $applyTo)) {
$applyTo = XXXCustomiseProductInfoModelProductTypeCustomtypecode::TYPE_ID;
$eavSetup->updateAttribute(
MagentoCatalogModelProduct::ENTITY,
$field,
'apply_to',
implode(',', $applyTo)
);
}
}
}
}


Please try and let me know if any issue.






share|improve this answer
























  • Still not working

    – Mano M
    Dec 18 '18 at 6:09











  • are you getting any error ? in exception log or system log ?

    – Aasim Goriya
    Dec 18 '18 at 6:11













  • After clearing cache its working fine.....thanks.

    – Mano M
    Dec 18 '18 at 6:13











  • Its neccessary to add installdata and price model for new product?

    – Mano M
    Dec 18 '18 at 6:18











  • Installdata is necessary but price model is not

    – Aasim Goriya
    Dec 18 '18 at 6:21














3












3








3







Please try below code to create custom product type.



In your etc/product_types.xml add following code



<?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 label="Customtype" modelInstance="XXXCustomiseProductInfoModelProductTypeCustomtypecode" name="customtypecode">
<priceModel instance="XXXCustomiseProductInfoModelProductPrice"/>
</type>
</config>


Create price model Model/Product/Price.php and add following code



<?php
namespace XXXCustomiseProductInfoModelProduct;

class Price extends MagentoCatalogModelProductTypePrice
{

}


In your Model/Product/Type/Customtypecode.php add following code



<?php
namespace XXXCustomiseProductInfoModelProductType;

class Customtypecode extends MagentoCatalogModelProductTypeSimple
{

const TYPE_ID = 'customtypecode';

/**
* {@inheritdoc}
*/
public function deleteTypeSpecificData(MagentoCatalogModelProduct $product)
{
// method intentionally empty
}
}


Add following code in Setup/InstallData.php



<?php    
namespace XXXCustomiseProductInfoSetup;

use MagentoFrameworkSetupInstallDataInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupModuleDataSetupInterface;
use MagentoEavSetupEavSetup;
use MagentoEavSetupEavSetupFactory;

class InstallData implements InstallDataInterface
{

private $eavSetupFactory;

/**
* Constructor
*
* @param MagentoEavSetupEavSetupFactory $eavSetupFactory
*/
public function __construct(EavSetupFactory $eavSetupFactory)
{
$this->eavSetupFactory = $eavSetupFactory;
}

/**
* {@inheritdoc}
*/
public function install(
ModuleDataSetupInterface $setup,
ModuleContextInterface $context
) {
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);

// associate these attributes with new product type
$fieldList = [
'price',
'special_price',
'special_from_date',
'special_to_date',
'minimal_price',
'cost',
'tier_price',
'weight',
];

// make these attributes applicable to new product type
foreach ($fieldList as $field) {
$applyTo = explode(
',',
$eavSetup->getAttribute(MagentoCatalogModelProduct::ENTITY, $field, 'apply_to')
);
if (!in_array(XXXCustomiseProductInfoModelProductTypeCustomtypecode::TYPE_ID, $applyTo)) {
$applyTo = XXXCustomiseProductInfoModelProductTypeCustomtypecode::TYPE_ID;
$eavSetup->updateAttribute(
MagentoCatalogModelProduct::ENTITY,
$field,
'apply_to',
implode(',', $applyTo)
);
}
}
}
}


Please try and let me know if any issue.






share|improve this answer













Please try below code to create custom product type.



In your etc/product_types.xml add following code



<?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 label="Customtype" modelInstance="XXXCustomiseProductInfoModelProductTypeCustomtypecode" name="customtypecode">
<priceModel instance="XXXCustomiseProductInfoModelProductPrice"/>
</type>
</config>


Create price model Model/Product/Price.php and add following code



<?php
namespace XXXCustomiseProductInfoModelProduct;

class Price extends MagentoCatalogModelProductTypePrice
{

}


In your Model/Product/Type/Customtypecode.php add following code



<?php
namespace XXXCustomiseProductInfoModelProductType;

class Customtypecode extends MagentoCatalogModelProductTypeSimple
{

const TYPE_ID = 'customtypecode';

/**
* {@inheritdoc}
*/
public function deleteTypeSpecificData(MagentoCatalogModelProduct $product)
{
// method intentionally empty
}
}


Add following code in Setup/InstallData.php



<?php    
namespace XXXCustomiseProductInfoSetup;

use MagentoFrameworkSetupInstallDataInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupModuleDataSetupInterface;
use MagentoEavSetupEavSetup;
use MagentoEavSetupEavSetupFactory;

class InstallData implements InstallDataInterface
{

private $eavSetupFactory;

/**
* Constructor
*
* @param MagentoEavSetupEavSetupFactory $eavSetupFactory
*/
public function __construct(EavSetupFactory $eavSetupFactory)
{
$this->eavSetupFactory = $eavSetupFactory;
}

/**
* {@inheritdoc}
*/
public function install(
ModuleDataSetupInterface $setup,
ModuleContextInterface $context
) {
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);

// associate these attributes with new product type
$fieldList = [
'price',
'special_price',
'special_from_date',
'special_to_date',
'minimal_price',
'cost',
'tier_price',
'weight',
];

// make these attributes applicable to new product type
foreach ($fieldList as $field) {
$applyTo = explode(
',',
$eavSetup->getAttribute(MagentoCatalogModelProduct::ENTITY, $field, 'apply_to')
);
if (!in_array(XXXCustomiseProductInfoModelProductTypeCustomtypecode::TYPE_ID, $applyTo)) {
$applyTo = XXXCustomiseProductInfoModelProductTypeCustomtypecode::TYPE_ID;
$eavSetup->updateAttribute(
MagentoCatalogModelProduct::ENTITY,
$field,
'apply_to',
implode(',', $applyTo)
);
}
}
}
}


Please try and let me know if any issue.







share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 18 '18 at 5:50









Aasim GoriyaAasim Goriya

3,6721738




3,6721738













  • Still not working

    – Mano M
    Dec 18 '18 at 6:09











  • are you getting any error ? in exception log or system log ?

    – Aasim Goriya
    Dec 18 '18 at 6:11













  • After clearing cache its working fine.....thanks.

    – Mano M
    Dec 18 '18 at 6:13











  • Its neccessary to add installdata and price model for new product?

    – Mano M
    Dec 18 '18 at 6:18











  • Installdata is necessary but price model is not

    – Aasim Goriya
    Dec 18 '18 at 6:21



















  • Still not working

    – Mano M
    Dec 18 '18 at 6:09











  • are you getting any error ? in exception log or system log ?

    – Aasim Goriya
    Dec 18 '18 at 6:11













  • After clearing cache its working fine.....thanks.

    – Mano M
    Dec 18 '18 at 6:13











  • Its neccessary to add installdata and price model for new product?

    – Mano M
    Dec 18 '18 at 6:18











  • Installdata is necessary but price model is not

    – Aasim Goriya
    Dec 18 '18 at 6:21

















Still not working

– Mano M
Dec 18 '18 at 6:09





Still not working

– Mano M
Dec 18 '18 at 6:09













are you getting any error ? in exception log or system log ?

– Aasim Goriya
Dec 18 '18 at 6:11







are you getting any error ? in exception log or system log ?

– Aasim Goriya
Dec 18 '18 at 6:11















After clearing cache its working fine.....thanks.

– Mano M
Dec 18 '18 at 6:13





After clearing cache its working fine.....thanks.

– Mano M
Dec 18 '18 at 6:13













Its neccessary to add installdata and price model for new product?

– Mano M
Dec 18 '18 at 6:18





Its neccessary to add installdata and price model for new product?

– Mano M
Dec 18 '18 at 6:18













Installdata is necessary but price model is not

– Aasim Goriya
Dec 18 '18 at 6:21





Installdata is necessary but price model is not

– Aasim Goriya
Dec 18 '18 at 6:21


















draft saved

draft discarded




















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f254969%2fhow-to-create-a-new-product-type-in-magento2%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

To store a contact into the json file from server.js file using a class in NodeJS

Redirect URL with Chrome Remote Debugging Android Devices

Dieringhausen