1

Add new attribute in product create page in admin side

How can I save value from this dropdown?

here is my product_form.xml

<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
 <fieldset name="product-details">
 <field name="featured_category_ids" sortOrder="100" formElement="select" component="Magento_Ui/js/form/element/ui-select">
 <argument name="data" xsi:type="array">
 <item name="config" xsi:type="array">
 <item name="filterOptions" xsi:type="boolean">true</item>
 <item name="showCheckbox" xsi:type="boolean">true</item>
 <item name="disableLabel" xsi:type="boolean">true</item>
 <item name="multiple" xsi:type="boolean">true</item>
 <item name="levelsVisibility" xsi:type="number">1</item>
 <item name="listens" xsi:type="array">
 <item name="${ $.namespace }.${ $.namespace }:responseData" xsi:type="string">setParsed</item>
 </item>
 </item>
 </argument>
 <settings>
 <label translate="true">Featured Categories</label>
 <dataType>text</dataType>
 <elementTmpl>ui/grid/filters/elements/ui-select</elementTmpl>
 </settings>
 <formElements>
 <select>
 <settings>
 <options class="Magento\Catalog\Ui\Component\Product\Form\Categories\Options"/>
 </settings>
 </select>
 </formElements>
 </field>
 </fieldset>
</form>
asked Nov 18, 2021 at 9:02
4
  • 1
    how you create this attribute? Commented Nov 18, 2021 at 10:56
  • add this product_form.xml file in my module and its are visible in adminside but value not save Commented Nov 18, 2021 at 10:58
  • 1
    You need to just create the product attribute using magento methods only and assign that attributeset, rest things is manage by magneto it self. Commented Nov 18, 2021 at 11:00
  • can you sow me working example? or something like that? Commented Nov 18, 2021 at 11:01

2 Answers 2

1

You will need to create a product attribute and add it to the product's attribute set first.

Then, reference the attribute ID in your field dataScope like so:

 <field name="attribute_id" formElement="select">
 <settings>
 <dataScope>attribute_id</dataScope>
 <imports>
 <link name="linkedValue">${$.provider}:data.product.attribute_id</link>
 </imports>
 </settings>
 </field>

If the two IDs match, Magento will save the value.

answered May 30, 2022 at 9:27
0

should be hidden or visible? can you leave a more complete code for creating product_form.xml fields through and creating and saving an attribute? My code which doesn't save or output attribute

<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
 <fieldset name="product_duo" sortOrder="6">
 <settings>
 <label translate="true">Duo</label>
 <collapsible>true</collapsible>
 <opened>true</opened>
 <dataScope>product_duo</dataScope>
 </settings>
 <field name="duo_product" formElement="input" sortOrder="10">
 <settings>
 <visible>true</visible>
 <elementTmpl>ui/form/element/input</elementTmpl>
 <label translate="true">Duo product</label>
 <dataScope>duo_product</dataScope>
 <imports>
 <link name="linkedValue">${$.provider}:data.product.duo_product</link>
 </imports>
 </settings>
 </field>
 </fieldset>
</form>
$eavSetup->addAttribute(
 Product::ENTITY,
 'duo_product',
 [
 'type' => 'varchar',
 'backend' => '',
 'frontend' => '',
 'label' => __('Duo product'),
 'input' => 'hidden',
 'class' => '',
 'source' => '',
 'global' => ScopedAttributeInterface::SCOPE_STORE,
 'visible' => true,
 'required' => false,
 'user_defined' => false,
 'default' => '',
 'searchable' => false,
 'filterable' => false,
 'comparable' => false,
 'visible_on_front' => false,
 'unique' => false,
 'apply_to' => '',
 'is_configurable' => false,
 ]

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.