简体   繁体   中英

Magento2 Add new field in product attribute edit form

I want to add new dropdown field in product attribute edit/new form page. I have created a module with ui_component file but my new field is not showing on the page, no errors as site is in developer mode.

These are my module files:

app/code/Vendor/Grouping/registration.php
    <?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Vendor_Grouping',
    __DIR__
);

app/code/Vendor/Grouping/etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Vendor_Grouping" setup_version="1.0.0">
        <module name="Magento_Catalog" />
    </module>
</config>

app/code/Vendor/Grouping/view/adminhtml/ui_component/product_attribute_add_form.xml
    <?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
     <fieldset name="base_fieldset">
         <field name="layered_group">
            <argument name="data" xsi:type="array">
                <item name="options" xsi:type="object">Magento\Catalog\Model\Product\Attribute\Source\Inputtype</item>
                <item name="config" xsi:type="array">
                    <item name="sortOrder" xsi:type="number">22</item>
                    <item name="dataType" xsi:type="string">string</item>
                    <item name="formElement" xsi:type="string">select</item>
                    <item name="source" xsi:type="string">product_attribute</item>
                    <item name="label" xsi:type="string" translate="true">Layered Nav Attribute Group</item>
                    <item name="dataScope" xsi:type="string">frontend_input</item>
                </item>
            </argument>
        </field>
     </fieldset>
</form>

In this file product_attribute_add_form.xml file i duplicate the frontend_input and change field name and labels.

How to add this new field in this form?

Have you run php bin/magento setup:upgrade ?

You need to run it to update add/etc/config.php . Your module has to be placed after Magento_Catalog.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM