How to make readonly SKU input in admin while product add/edit magento 2.3
Please help!
Thanks
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityHow to make readonly SKU input in admin while product add/edit magento 2.3
Please help!
Thanks
For disabled product SKU field in the admin.
Create di.xml
file under app/code/Vendor/Module/etc/adminhtml
with below content.
<?xml version="1.0"?>
<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="sku" xsi:type="array">
<item name="class" xsi:type="string">Vendor\Module\Ui\DataProvider\Product\Form\Modifier\Attributes</item>
<item name="sortOrder" xsi:type="number">1000</item>
</item>
</argument>
</arguments>
</virtualType>
</config>
And create Attributes.php
file under app/code/Vendor/Module/Ui/DataProvider/Product/Form/Modifier/
with below content.
<?php
namespace Vendor\Module\Ui\DataProvider\Product\Form\Modifier;
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
use Magento\Framework\Stdlib\ArrayManager;
class Attributes extends AbstractModifier
{
/**
* @var Magento\Framework\Stdlib\ArrayManager
*/
private $arrayManager;
/**
* @param ArrayManager $arrayManager
*/
public function __construct(
ArrayManager $arrayManager
) {
$this->arrayManager = $arrayManager;
}
/**
* modifyData
*
* @param array $data
* @return array
*/
public function modifyData(array $data)
{
return $data;
}
/**
* modifyMeta
*
* @param array $data
* @return array
*/
public function modifyMeta(array $meta)
{
$attribute = 'sku'; //attribute code to disable
$path = $this->arrayManager->findPath($attribute, $meta, null, 'children');
$meta = $this->arrayManager->set(
"{$path}/arguments/data/config/disabled",
$meta,
true
);
return $meta;
}
}
Thanks in advanced.