0

First, I created the UI component: Vendor/Module/view/adminhtml/ui_component/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">
 <container name="fieldname_container">
 <argument name="data" xsi:type="array">
 <item name="config" xsi:type="array">
 <item name="sortOrder" xsi:type="number">160</item>
 </item>
 </argument>
 <field name="fieldname" formElement="multiselect">
 <argument name="data" xsi:type="array">
 <item name="config" xsi:type="array">
 <item name="dataScope" xsi:type="string">fieldname</item>
 <item name="filterOptions" xsi:type="boolean">true</item>
 <item name="showCheckbox" xsi:type="boolean">true</item>
 <item name="disableLabel" xsi:type="boolean">false</item>
 <item name="multiple" xsi:type="boolean">true</item>
 </item>
 </argument>
 <settings>
 <validation>
 <rule name="validate-field" xsi:type="boolean">true</rule>
 </validation>
 <dataType>varchar</dataType>
 <label translate="true">Field label</label>
 <dataScope>fieldname</dataScope>
 </settings>
 <formElements>
 <multiselect>
 <settings>
 <options class="Vendor\Module\Model\Backend\Product\Source\FieldName"/>
 </settings>
 </multiselect>
 </formElements>
 </field>
 </container>
 </fieldset>
</form>

however when I save product the values of the custom attribute are not saved.

Created attribute and added it to product but now I have that field twice in product form. ( values are being saved )

If I remove created field from attribute set values are not being saved.

what is wrong here ?

ASQ
1,0707 silver badges17 bronze badges
asked Jul 19, 2019 at 9:58

1 Answer 1

0

Perhaps I misunderstand you. However if you use setup script you shouldn't need any XML. It's the same as manually adding product attribute via backend. The attribute data is in the db. No XML.

https://github.com/DominicWatts/Featured/blob/master/Setup/InstallData.php#L38

 $eavSetup->addAttribute(
 \Magento\Catalog\Model\Product::ENTITY,
 'featured',
 [
 'type' => 'int',
 'backend' => '',
 'frontend' => '',
 'label' => 'Featured Product',
 'input' => 'boolean',
 'class' => '',
 'source' => '',
 'global' => 0,
 'visible' => true,
 'required' => false,
 'user_defined' => true,
 'default' => null,
 'searchable' => false,
 'filterable' => false,
 'comparable' => false,
 'visible_on_front' => false,
 'used_in_product_listing' => false,
 'unique' => false,
 'apply_to' => '',
 'system' => 1,
 'group' => 'General',
 'option' => ['values' => [""]]
 ]
 );
answered Jul 21, 2019 at 23:37
1
  • i need xml for this attribute, need to add additional html, logic and some javascript. Commented Jul 22, 2019 at 6:54

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.