0

I am trying to modify sections for specific product types. How can I add or remove sections like "Design" or "Search Engine Optimization"?

0

Here is an answer I found for deleting sections. New sections can be injected in the same way:

in adminhtml/di.xml

<?xml version="1.0" encoding="UTF-8"?>
<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="product_form_eav" xsi:type="array">
                    <item name="class" xsi:type="string">Namespace\Module\Ui\DataProvider\Product\Form\Modifier\Eav</item>
                    <item name="sortOrder" xsi:type="number">2000</item>
                </item>
            </argument>
        </arguments>
    </virtualType>
</config>

then:

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

use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
use Magento\Catalog\Model\Locator\LocatorInterface;
use Magento\Framework\App\RequestInterface;

Class Eav extends AbstractModifier
{
    /**
     * @var LocatorInterface
     */
    protected $locator;

    /**
     * @var RequestInterface
     */
    protected $request;

    /**
     * Eav constructor.
     * @param LocatorInterface $locator
     * @param RequestInterface $request
     */
    public function __construct(
        LocatorInterface $locator,
        RequestInterface $request
    ) {
        $this->locator = $locator;
        $this->request = $request;
    }

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

    /**
     * @param array $meta
     * @return array
     */
    public function modifyMeta(array $meta)
    {
        $productType = $this->getProductType();
        if ($productType === \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE) {
            $disabledGroups = ['search-engine-optimization', 'design'];

            foreach ($disabledGroups as $disabledGroup) {
                unset($meta[$disabledGroup]);
            }
        }

        return $meta
    }

    /**
     * Get product type
     * @return null|string
     */
    private function getProductType()
    {
        return (string)$this->request->getParam('type', $this->locator->getProduct()->getTypeId());
    }
}

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.