How to create a new product type in magento2











up vote
2
down vote

favorite
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
























  • Can you see any error in exception.log ?
    – Supravat M
    2 hours ago










  • 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
    2 hours ago










  • In console...ReferenceError: Unable to process binding "if: function(){return label }" Message: label is not defined
    – Mano M
    2 hours ago










  • @ManoM can you please update your question with product_types.xml and other files which you have created.
    – Ramkishan Suthar
    2 hours ago












  • updated my post..
    – Mano M
    2 hours ago















up vote
2
down vote

favorite
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
























  • Can you see any error in exception.log ?
    – Supravat M
    2 hours ago










  • 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
    2 hours ago










  • In console...ReferenceError: Unable to process binding "if: function(){return label }" Message: label is not defined
    – Mano M
    2 hours ago










  • @ManoM can you please update your question with product_types.xml and other files which you have created.
    – Ramkishan Suthar
    2 hours ago












  • updated my post..
    – Mano M
    2 hours ago













up vote
2
down vote

favorite
1









up vote
2
down vote

favorite
1






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 2 hours ago

























asked 2 hours ago









Mano M

752117




752117












  • Can you see any error in exception.log ?
    – Supravat M
    2 hours ago










  • 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
    2 hours ago










  • In console...ReferenceError: Unable to process binding "if: function(){return label }" Message: label is not defined
    – Mano M
    2 hours ago










  • @ManoM can you please update your question with product_types.xml and other files which you have created.
    – Ramkishan Suthar
    2 hours ago












  • updated my post..
    – Mano M
    2 hours ago


















  • Can you see any error in exception.log ?
    – Supravat M
    2 hours ago










  • 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
    2 hours ago










  • In console...ReferenceError: Unable to process binding "if: function(){return label }" Message: label is not defined
    – Mano M
    2 hours ago










  • @ManoM can you please update your question with product_types.xml and other files which you have created.
    – Ramkishan Suthar
    2 hours ago












  • updated my post..
    – Mano M
    2 hours ago
















Can you see any error in exception.log ?
– Supravat M
2 hours ago




Can you see any error in exception.log ?
– Supravat M
2 hours ago












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
2 hours ago




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
2 hours ago












In console...ReferenceError: Unable to process binding "if: function(){return label }" Message: label is not defined
– Mano M
2 hours ago




In console...ReferenceError: Unable to process binding "if: function(){return label }" Message: label is not defined
– Mano M
2 hours ago












@ManoM can you please update your question with product_types.xml and other files which you have created.
– Ramkishan Suthar
2 hours ago






@ManoM can you please update your question with product_types.xml and other files which you have created.
– Ramkishan Suthar
2 hours ago














updated my post..
– Mano M
2 hours ago




updated my post..
– Mano M
2 hours ago










1 Answer
1






active

oldest

votes

















up vote
3
down vote



accepted










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
    1 hour ago










  • are you getting any error ? in exception log or system log ?
    – Aasim Goriya
    1 hour ago












  • After clearing cache its working fine.....thanks.
    – Mano M
    1 hour ago










  • Its neccessary to add installdata and price model for new product?
    – Mano M
    1 hour ago










  • Installdata is necessary but price model is not
    – Aasim Goriya
    1 hour ago











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',
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








up vote
3
down vote



accepted










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
    1 hour ago










  • are you getting any error ? in exception log or system log ?
    – Aasim Goriya
    1 hour ago












  • After clearing cache its working fine.....thanks.
    – Mano M
    1 hour ago










  • Its neccessary to add installdata and price model for new product?
    – Mano M
    1 hour ago










  • Installdata is necessary but price model is not
    – Aasim Goriya
    1 hour ago















up vote
3
down vote



accepted










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
    1 hour ago










  • are you getting any error ? in exception log or system log ?
    – Aasim Goriya
    1 hour ago












  • After clearing cache its working fine.....thanks.
    – Mano M
    1 hour ago










  • Its neccessary to add installdata and price model for new product?
    – Mano M
    1 hour ago










  • Installdata is necessary but price model is not
    – Aasim Goriya
    1 hour ago













up vote
3
down vote



accepted







up vote
3
down vote



accepted






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 1 hour ago









Aasim Goriya

2,2691632




2,2691632












  • Still not working
    – Mano M
    1 hour ago










  • are you getting any error ? in exception log or system log ?
    – Aasim Goriya
    1 hour ago












  • After clearing cache its working fine.....thanks.
    – Mano M
    1 hour ago










  • Its neccessary to add installdata and price model for new product?
    – Mano M
    1 hour ago










  • Installdata is necessary but price model is not
    – Aasim Goriya
    1 hour ago


















  • Still not working
    – Mano M
    1 hour ago










  • are you getting any error ? in exception log or system log ?
    – Aasim Goriya
    1 hour ago












  • After clearing cache its working fine.....thanks.
    – Mano M
    1 hour ago










  • Its neccessary to add installdata and price model for new product?
    – Mano M
    1 hour ago










  • Installdata is necessary but price model is not
    – Aasim Goriya
    1 hour ago
















Still not working
– Mano M
1 hour ago




Still not working
– Mano M
1 hour ago












are you getting any error ? in exception log or system log ?
– Aasim Goriya
1 hour ago






are you getting any error ? in exception log or system log ?
– Aasim Goriya
1 hour ago














After clearing cache its working fine.....thanks.
– Mano M
1 hour ago




After clearing cache its working fine.....thanks.
– Mano M
1 hour ago












Its neccessary to add installdata and price model for new product?
– Mano M
1 hour ago




Its neccessary to add installdata and price model for new product?
– Mano M
1 hour ago












Installdata is necessary but price model is not
– Aasim Goriya
1 hour ago




Installdata is necessary but price model is not
– Aasim Goriya
1 hour ago


















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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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

Plaza Victoria

In PowerPoint, is there a keyboard shortcut for bulleted / numbered list?

How to put 3 figures in Latex with 2 figures side by side and 1 below these side by side images but in...