1

How can I set opened state to inactive for bundle items tab in product edit page Magento 2 so that the tab is loaded only on click, not on page load. For more information: https://stackoverflow.com/questions/41947465/how-to-close-all-accordions-in-magento2-admin-product-detail-by-default

Thanks in Advance!

0

You can try to Overriding ( as described below ) the class Magento\Bundle\Ui\DataProvider\Product\Form\Modifier\BundlePane for your requirement.

I assume you will create a custom module name "Vendor_Module" to do this customization tasks

step 1) Create di.xml under

/app/code/Vendor/Module/etc/adminhtml/

File : di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Bundle\Ui\DataProvider\Product\Form\Modifier\BundlePanel" 
                type="Vendor\Module\Ui\DataProvider\Product\Form\Modifier\BundlePanel" />
</config>

step 2: Create BundlePanel.php under

/app/code/Vendor/Module/Ui/DataProvider/Product/Form/Modifier/

File : BundlePanel.php

<?php

namespace Vendor\Module\Ui\DataProvider\Product\Form\Modifier;


class BundlePanel extends \Magento\Bundle\Ui\DataProvider\Product\Form\Modifier\BundlePanel
{


    /**
     * {@inheritdoc}
     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
     */
    public function modifyMeta(array $meta)
    {
        $meta = parent::modifyMeta($meta);
        $path = $this->arrayManager->findPath(static::CODE_BUNDLE_DATA, $meta, null, 'children');
        $meta = $this->arrayManager->merge(
            $path,
            $meta,
            [
                'arguments' => [
                    'data' => [
                        'config' => [
                            'dataScope' => '',
                            'opened' => false,
                            'sortOrder' => $this->getNextGroupSortOrder(
                                $meta,
                                static::GROUP_CONTENT,
                                static::SORT_ORDER
                            )
                        ],
                    ],
                ],
            ]
           );
        return $meta;
    }


}

step 3: Run di compile commnad

sudo php bin/magento setup:di:compile

step 4: clean your Magento cache

========================================================

Please Note:

To Show/hide the Bundle Items tab, Please change $meta array key value to true/false in the Overriding class file Vendor\Module\Ui\DataProvider\Product\Form\Modifier\BundlePanel.php as follows :

'opened' => false,

========================================================

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.