0

When I create new product type and extend Bundle, I don`t have "Bundle Items" tab, how I can get the same functionality in my custom product type like in Bundle product? enter image description here

product_type.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Catalog:etc/product_types.xsd"> <type name="super_bundle" label="Super Bundle Product" modelInstance="Vendor\Module\Model\Product\Type" composite='true' indexPriority="40" sortOrder="50"> <priceModel instance="Magento\Bundle\Model\Product\Price" /> <indexerModel instance="Magento\Bundle\Model\ResourceModel\Indexer\Price" /> <stockIndexerModel instance="Magento\Bundle\Model\ResourceModel\Indexer\Stock" /> <allowedSelectionTypes> <type name="virtual" /> </allowedSelectionTypes> <customAttributes> <attribute name="refundable" value="true"/> </customAttributes> </type> </config>

When I use

----------

  • i have the same problem. Did you solve it? – Wojciech Ka Jul 24 '18 at 21:08
0

I hope you were both able to Figure out your issue, If not I believe the Following should be the fix.

<vendor>/<module>/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="custom_bundle" label="Custom Bundle Product" modelInstance="<vendor>\<module>\Model\Product\Type" composite='true' indexPriority="40" sortOrder="50">
        <priceModel instance="Magento\Bundle\Model\Product\Price" />
        <indexerModel instance="Magento\Bundle\Model\ResourceModel\Indexer\Price" />
        <stockIndexerModel instance="Magento\Bundle\Model\ResourceModel\Indexer\Stock" />
        <allowedSelectionTypes>
            <type name="simple" />
            <type name="virtual" />
        </allowedSelectionTypes>
        <customAttributes>
            <attribute name="refundable" value="true"/>
        </customAttributes>
    </type>
</config>

<vendor>/<module>/Model/Product/Type.php:

<?php

namespace <vendor>\<module>\Model\Product;

/**
 * Class Type
 * @package <vendor>\<module>\Model\Product
 */
class Type extends \Magento\Bundle\Model\Product\Type {

    const TYPE_CODE = 'custom_bundle';

    // Class Intentionally left blank
}

<vendor>/<module>/Setup/InstallData.php:

namespace <vendor>\<module>\Setup;

use Magento\Eav\Setup\EavSetup;
use \Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Catalog\Model\Product;
use <vendor>\<module>\Model\Product\Type as CustomPoductType;

/**
 * Class InstallData
 * @package <vendor>\<module>\Setup
 */
class InstallData implements InstallDataInterface
{
    /**
     * EAV setup factory
     *
     * @var EavSetupFactory
     */
    private $eavSetupFactory;

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

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

        $fieldList = [
            'price',
            'special_price',
            'special_from_date',
            'special_to_date',
            'minimal_price',
            'cost',
            'tier_price',
            'weight',
            'price_type',
            'sku_type',
            'weight_type',
            'price_view',
            'shipment_type',
        ];

        foreach ($fieldList as $field) {
            $applyTo = explode(',', $eavSetup->getAttribute(Product::ENTITY, $field, 'apply_to'));

            if (!in_array(CustomPoductType::TYPE_CODE, $applyTo)) {
                $applyTo[] = CustomPoductType::TYPE_CODE;
                $eavSetup->updateAttribute(
                    Product::ENTITY,
                    $field,
                    'apply_to',
                    implode(',', $applyTo)
                );
            }
        }
    }
}

From your question i think the main part you are missing is the EAV Attributes assignment. if you were to take a look at the Magento_Bundle module Setup/InstallData.php you will see that this has a list of existing attributes that it assigns plus creates some new ones, it is the new attributes that are required, specifically shipment_type for the highlighted area in the screenshot.

  • add option button still missing..... – Arslan Tabassum Jan 25 at 19:37

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.