I’m trying to store data from a custom uiComponent to and Custom Product Attribute. The product attribute is in the database, and the uiComponent (with options) is showing in the Admin with the product in it’s own tab. However, it’s not saving the selection. How can I get this to work?
InstallData.php
<?php
namespace MyLabelsSetup;
use MagentoEavSetupEavSetup;
use MagentoEavSetupEavSetupFactory;
use MagentoFrameworkSetupInstallDataInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupModuleDataSetupInterface;
class InstallData implements InstallDataInterface
{
private $eavSetupFactory;
public function __construct(EavSetupFactory $eavSetupFactory)
{
$this->eavSetupFactory = $eavSetupFactory;
}
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$eavSetup->addAttribute(
MagentoCatalogModelProduct::ENTITY,
'my_product_label',
[
'type' => 'text',
'backend' => '',
'frontend' => '',
'label' => 'Product Label',
'input' => 'text',
'class' => '',
'source' => '',
'global' => MagentoEavModelEntityAttributeScopedAttributeInterface::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => false,
'default' => '',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'used_in_product_listing' => true,
'unique' => false,
'apply_to' => ''
]
);
}
}
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="labelstab" sortOrder="20">
<settings>
<collapsible>true</collapsible>
<label translate="true">Product Image Labels</label>
</settings>
<field name="my_product_label">
<argument name="data" xsi:type="array">
<item name="options" xsi:type="object">
MyLabelsModelConfigSourceProductLabels</item>
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Labels</item>
<item name="formElement" xsi:type="string">select</item>
<item name="component" xsi:type="string">Magento_Ui/js/form/element/ui-select</item>
<item name="elementTmpl" xsi:type="string"> ui/grid/filters/elements/ui-select</item>
<item name="dataScope" xsi:type="string">my_product_label</item>
<item name="filterOptions" xsi:type="boolean">true</item>
<item name="chipsEnabled" 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="sortOrder" xsi:type="number">30</item>
<item name="validation" xsi:type="array">
<item name="required-entry" xsi:type="boolean">false</item>
</item>
<item name="links" xsi:type="array">
<item name="linkedValue" xsi:type="string">
${$.provider}:data.product.my_product_label</item>
</item>
</item>
</argument>
</field>
</fieldset>
</form>