【发布时间】:2016-12-21 10:29:01
【问题描述】:
我想在 magento2 的产品编辑表单中添加一个新的下拉列表。数据应该来自我在自定义模块中创建的自定义表。我该怎么做,那里有很好的例子或教程吗?
我尝试创建一个观察者,如下所示:
<?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>
观察者看起来像这样:
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?!";
}
...
}
谢谢!
【问题讨论】:
-
您需要创建一个下拉类型的新产品属性,并使用自定义模型指定。
-
如何使用自定义模型指定属性?