I want to add a new dropdown to the product edit form in magento2. The data should come from a custom table I created in a custom module. How do I do this, is there a good example or tutorial out there?
I tried to create an observer, like this:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="adminhtml_catalog_product_attribute_edit_prepare_form">
<observer name="custom_product_fields" instance="Vendorname\Custom\Observer\CatalogProductEditPrepareForm"/>
<!-- CatalogProductEditPrepareForm is name of class in which we'll add custom fields in form-->
</event>
</config>
And the Observer looks like this:
class CatalogProductEditPrepareForm implements ObserverInterface
{
protected $_coreRegistry;
public function __construct(\Magento\Framework\Registry $coreRegistry) {
$this->_coreRegistry = $coreRegistry;
}
public function execute(\Magento\Framework\Event\Observer $observer){
echo "why is this not called?!";
}
...
}
Thanks!
You have create attribute with InstallData.php file in custom extension, Code is here.
Above code create product attribute, and you need to create custom source file here,