如图我们需要给所有Attribute扩展以下2种属性
etc/adminhtml/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Catalog\Block\Adminhtml\Product\Attribute\Edit\Tab\Front">
<plugin name="extension_attribute_edit_form" type="Pje\Catalog\Plugin\Block\Adminhtml\Product\Attribute\Edit\Tab\Front" sortOrder="1"/>
</type>
</config>
etc/db_schema.xml
<?xml version="1.0"?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
<table name="catalog_eav_attribute" resource="default" engine="innodb" comment="Catalog EAV Attribute Table">
<column xsi:type="smallint" name="used_tip" unsigned="true" nullable="false"
identity="false" default="0" comment="Custom tips"/>
<column xsi:type="smallint" name="show_mode" unsigned="true" nullable="false"
identity="false" default="0" comment="Custom mode"/>
</table>
</schema>
app\code\Pje\Catalog\Plugin\Block\Adminhtml\Product\Attribute\Edit\Tab\Front.php
<?php
namespace Pje\Catalog\Plugin\Block\Adminhtml\Product\Attribute\Edit\Tab;
class Front
{
protected $custom;
protected $_coreRegistry;
public function __construct(
\Magento\Config\Model\Config\Source\Yesno $custom,
\Magento\Framework\Registry $_coreRegistry
) {
$this->custom = $custom;
$this->_coreRegistry = $_coreRegistry;
}
public function aroundGetFormHtml(
\Magento\Catalog\Block\Adminhtml\Product\Attribute\Edit\Tab\Front $subject,
\Closure $proceed
)
{
$attributeObject = $this->getAttributeObject();
$customSource = $this->custom->toOptionArray();
$form = $subject->getForm();
$fieldset = $form->getElement('front_fieldset');
$fieldset->addField(
'used_tip',
'select',
[
'name' => 'used_tip',
'label' => __('Used Tip'),
'title' => __('Used Tip'),
'value' => $attributeObject->getData('used_tip'),
'values' => $customSource,
]
);
$fieldset->addField(
'show_mode',
'select',
[
'name' => 'show_mode',
'label' => __('Show Mode'),
'title' => __('Show Mode'),
'value' => $attributeObject->getData('show_mode'),
'values' => array(
array('label' => 'None', 'value' => 0),
array('label' => 'Pic Mode', 'value' => 1),
array('label' => 'Color Mode', 'value' => 2),
array('label' => 'Text Mode', 'value' => 3),
array('label' => 'Circle Mode', 'value' => 4),
array('label' => 'Drop Mode', 'value' => 5),
array('label' => 'Custom Mode', 'value' => 6),
),
]
);
return $proceed();
}
private function getAttributeObject()
{
return $this->_coreRegistry->registry('entity_attribute');
}
}
最后执行命令:sh pub/shell/deploy_all.sh