0

Is it possible to add a new tab in the admin product edit page, but just for simple products? I was able to add a tab using ui_component, but I can't figure out how to add this just for simple products

view/adminhtml/ui_component/product_form.xml
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <fieldset name="new_tab">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="label" xsi:type="string">NEW TAB NAME</item>
                <item name="sortOrder" xsi:type="number">200</item>
                <item name="collapsible" xsi:type="boolean">true</item>
            </item>
        </argument>
        <insertListing name="new_tab_listing">
            <settings>
                <dataLinks>
                    <exports>false</exports>
                    <imports>true</imports>
                </dataLinks>
                <externalProvider>new_tab_listing.new_tab_listing_data_source</externalProvider>
                <autoRender>true</autoRender>
                <dataScope>new_tab_listing</dataScope>
                <ns>new_tab_listing</ns>
                <imports>
                    <link name="product_id">${ $.provider }:data.product.current_product_id</link>
                </imports>
                <exports>
                    <link name="product_id">${ $.externalProvider }:params.product_id</link>
                </exports>
            </settings>
        </insertListing>
    </fieldset>
</form>

1 Answer 1

0

I fixed this by adding a meta data modifier

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <virtualType name="Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Pool">
        <arguments>
            <argument name="modifiers" xsi:type="array">
                <item name="new_tab" xsi:type="array">
                    <item name="class" xsi:type="string">Vendor\ModuleName\Ui\DataProvider\Product\Form\Modifier\NewTab</item>
                    <item name="sortOrder" xsi:type="number">90</item>
                </item>
            </argument>
        </arguments>
    </virtualType>
</config>
class NewTab extends AbstractModifier
{
    public function __construct(
        private readonly LocatorInterface $locator
    ) {
    }

    /**
     * @inheritdoc
     */
    public function modifyData(array $data): array
    {
        return $data;
    }

    /**
     * @inheritdoc
     */
    public function modifyMeta(array $meta)
    {
        $meta['new_tab']['arguments']['data']['config']['visible'] = $this->isSimpleProduct();

        return $meta;
    }

    private function isSimpleProduct(): bool
    {
        return $this->locator->getProduct()->getTypeId() === 'simple';
    }
}

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.