2

I created a new product type like "License Product" extend from "Virtual Product". I can place an order with this product type in frontend, but i can't add this product to order in backend.

Any help will be appreciated.

This is my code:

Setup/InstallData.php

class InstallData implements InstallDataInterface
{
    private $eavSetupFactory;

    public function __construct(EavSetupFactory $eavSetupFactory)
    {
        $this->eavSetupFactory = $eavSetupFactory;
    }

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


        $fieldList = [
            'price',
            'special_price',
            'special_from_date',
            'special_to_date',
            'minimal_price',
            'cost',
            'tier_price',
            'weight',
        ];

        foreach ($fieldList as $field) {
            $applyTo = explode(
               ',',
               $eavSetup->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $field, 'apply_to')
        );
        if (!in_array('license', $applyTo)) {
            $applyTo[] = 'license';
            $eavSetup->updateAttribute(
                \Magento\Catalog\Model\Product::ENTITY,
                $field,
                'apply_to',
                implode(',', $applyTo)
            );
        }
    }
  }
}

etc/product_types.xml

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

  • can you explain more? – Shakir Khan Mar 11 '16 at 11:25
  • Ex: I created a new product with type "License Product" and it have id as 2000. But when i can't find this product when i want add it to an orders in admin panel. – Thao Pham Mar 11 '16 at 16:34
3
+100

as far as I see, when the collection of available product types is prepared, the list is fetched from Magento\Sales\Model\Config::getAvailableProductTypes() which in turns searches for XML configuration under order/available_product_types nodes.

In other words: did you define a sales.xml file under your module's etc folder made like this?

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Sales:etc/sales.xsd">
    <order>
        <available_product_type name="license"/>
    </order>
</config>

Hope it throws some light.

| improve this answer | |
  • Glad it was helpful! Thank you for the points. – Alessandro Ronchi Mar 15 '16 at 7:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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