How to create a product attribute in Magento 2.3 via declarative schema. I have tried below code but the input element is not visible on the form.
<?php
namespace Rokanthemes\Updates\Setup\Patch\Data;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Setup\Patch\PatchVersionInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Customer\Model\Customer;
use Magento\Customer\Setup\CustomerSetupFactory;
use Magento\Eav\Model\Entity\Attribute\SetFactory as AttributeSetFactory;
use Magento\Framework\DB\Ddl\Table;
class AddAttributes implements DataPatchInterface
{
protected $_moduleDataSetup;
protected $_customerSetupFactory;
protected $_attributeSetFactory;
public function __construct(
ModuleDataSetupInterface $moduleDataSetup,
CustomerSetupFactory $customerSetupFactory,
AttributeSetFactory $attributeSetFactory
)
{
$this->_moduleDataSetup = $moduleDataSetup;
$this->_customerSetupFactory = $customerSetupFactory;
$this->_attributeSetFactory = $attributeSetFactory;
}
public function apply()
{
$customerSetup = $this->_customerSetupFactory->create(['setup' => $this->_moduleDataSetup]);
$customerEntity = $customerSetup->getEavConfig()->getEntityType(Customer::ENTITY);
$attributeSetId = $customerEntity->getDefaultAttributeSetId();
$attributeSet = $this->_attributeSetFactory->create();
$attributeSet->getDefaultGroupId($attributeSetId);
$customerSetup->addAttribute(Customer::ENTITY, 'news_from_date', array(
'type' => Table::TYPE_DATE,
'label' => 'New from date',
'input' => 'date',
'required' => 1,
'type' => 'static',
'visible' => true
));
}
public function getAliases()
{
return [];
}
public static function getDependencies()
{
return [
];
}
}
Thanks for the help.