3

I am trying to add new product type in magento 2 but when i click on product type say Demo Product from the Add Product Select box than it will throw below error.

The requested component ("demo_product") is not found. Before using, you must add the implementation.

Product_types.xml code below

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Catalog:etc/product_types.xsd">
<type name="demoproduct" label="Demo Product" modelInstance="Test\Demo\Model\Product\Type\DemoProduct" composite="false" isQty="true" canUseQtyDecimals="false" sortOrder="80">
    <priceModel instance="Test\Demo\Model\Product\Type\Price"/>
    <customAttributes>
        <attribute name="refundable" value="true"/>
        <attribute name="is_real_product" value="false"/>
    </customAttributes>
</type>

Here is Modal Instance

    namespace Test\Demo\Model\Product\Type;
class DemoProduct extends \Magento\Catalog\Model\Product\Type\Virtual
{
    const TYPE_GIFTCARD = 'demoproduct';    
}

Can you please tell me what is missing?

I am using Magento 2.1.

Thanks in advance.

3
  • Kindly update your code so issue can be triggered
    – Rushvi
    Jul 26, 2016 at 5:08
  • I have updated the code. Jul 26, 2016 at 5:23
  • I think your model class should extended from the Magento\Catalog\Model\Product\Type\AbstractType. So the code will be like - class DemoProduct extends \Magento\Catalog\Model\Product\Type\AbstractType { }
    – Tejas Shah
    Jul 26, 2016 at 6:47

1 Answer 1

2

I have made like below and is working fine at my end. Please update your code to extend method,

app/code/Vendorname/Modulename/etc/product_types.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../Catalog/etc/product_types.xsd">
    <type name="giftcard" label="GiftCard" modelInstance="Vendorname\Modulename\Model\Product\Type\Giftcard" indexPriority="25" sortOrder="25">

    </type>
</config>

app/code/Vendorname/Modulename/Model/Product/Type/Giftcard.php

<?php 

namespace Vendorname\Modulename\Model\Product\Type;

class Giftcard extends \Magento\Catalog\Model\Product\Type\AbstractType
{
    /**
     * Delete data specific for Simple product type
     *
     * @param \Magento\Catalog\Model\Product $product
     * @return void
     */
    public function deleteTypeSpecificData(\Magento\Catalog\Model\Product $product)
    {
    }
} ?>
2
  • Thanks for your answer but can you please tell me something about error The requested component ("demo_product") is not found. Before using, you must add the implementation. Jul 26, 2016 at 11:10
  • When you are getting this error?
    – Rushvi
    Jul 26, 2016 at 11:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.