0

I have created new field set with two fields in product form.

How do I save those fields in a separate table in Magento 2?

Please provide me a solution.

My code Vendor/Modulename/view/adminhtml/ui_component/product_form.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
 - Copyright © Magento, Inc. All rights reserved.
 - See COPYING.txt for license details.
 */
-->
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">

    <!--<dataSource name="dynamic_rows_data_source">
        <argument name="dataProvider" xsi:type="configurableObject">
            <argument name="class" xsi:type="string">Bss\DynamicRows\Model\DataProvider</argument>
            <argument name="name" xsi:type="string">dynamic_rows_data_source</argument>
            <argument name="primaryFieldName" xsi:type="string">row_id</argument>
            <argument name="requestFieldName" xsi:type="string">scope</argument>
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="submit_url" xsi:type="url" path="bss/row/save"/>
                </item>
            </argument>
        </argument>
        <argument name="data" xsi:type="array">
            <item name="js_config" xsi:type="array">
                <item name="component" xsi:type="string">Magento_Ui/js/form/provider</item>
            </item>
        </argument>
    </dataSource>-->
    <fieldset name="dynamic_rows_set" sortOrder="20">
        <settings>
            <label translate="true">Dynamic Product Options</label>
            <collapsible>true</collapsible>
            <opened>false</opened>
            <dataScope>sources</dataScope>
        </settings>
        <container name="dynamic_rows_container">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="component" xsi:type="string">Magento_Ui/js/dynamic-rows/dynamic-rows</item>
                    <item name="template" xsi:type="string">ui/dynamic-rows/templates/default</item>
                    <item name="componentType" xsi:type="string">dynamicRows</item>
                    <item name="recordTemplate" xsi:type="string">record</item>
                    <item name="addButtonLabel" xsi:type="string">Add Row</item>
                    <item name="deleteProperty" xsi:type="boolean">false</item>
                </item>
            </argument>
            <container name="record">
                <argument name="data" xsi:type="array">
                    <item name="config" xsi:type="array">
                        <item name="label" xsi:type="string" translate="true">Dynamic Rows</item>
                        <item name="component" xsi:type="string" translate="true">Magento_Ui/js/dynamic-rows/record
                        </item>
                        <item name="isTemplate" xsi:type="boolean">true</item>
                        <item name="is_collection" xsi:type="boolean">true</item>
                        <item name="showFallbackReset" xsi:type="boolean">false</item>
                    </item>
                </argument>
               <!-- <field name="row_id">
                    <argument name="data" xsi:type="array">
                        <item name="config" xsi:type="array">
                            <item name="dataType" xsi:type="string">text</item>
                            <item name="label" xsi:type="string" translate="true">ID</item>
                            <item name="visible" xsi:type="boolean">false</item>
                            <item name="dataType" xsi:type="string">text</item>
                            <item name="formElement" xsi:type="string">input</item>
                            <item name="dataScope" xsi:type="string">row_id</item>
                        </item>
                    </argument>
                </field>
               --> <field name="units_available">
                    <argument name="data" xsi:type="array">
                        <item name="config" xsi:type="array">
                            <item name="dataType" xsi:type="string">text</item>
                            <item name="label" xsi:type="string" translate="true">Units Available</item>
                            <item name="formElement" xsi:type="string">input</item>
                            <item name="dataScope" xsi:type="string">units_available</item>
                            <item name="showFallbackReset" xsi:type="boolean">false</item>
                            <item name="sortOrder" xsi:type="string">10</item>
                        </item>
                    </argument>
                </field>
                <field name="date_of_availability">
                    <argument name="data" xsi:type="array">
                        <item name="config" xsi:type="array">
                            <item name="filter" xsi:type="string">dateRange</item>
                            <item name="dataType" xsi:type="string">date</item>
                            <item name="formElement" xsi:type="string">input</item>
                            <item name="component" xsi:type="string">Magento_Ui/js/form/element/date</item>
                            <item name="label" xsi:type="string" translate="true">Date of Availability</item>
                            <item name="dataScope" xsi:type="string">date_of_availability</item>
                            <item name="disabled" xsi:type="boolean">false</item>
                            <item name="options" xsi:type="array">
                                <item name="dateFormat" xsi:type="string">y-MM-dd</item>
                            </item>
                            <item name="sortOrder" xsi:type="string">30</item>
                        </item>
                    </argument>
                </field>
                <field name="position">
                    <argument name="data" xsi:type="array">
                        <item name="config" xsi:type="array">
                            <item name="dataType" xsi:type="string">number</item>
                            <item name="formElement" xsi:type="string">input</item>
                            <item name="componentType" xsi:type="string">field</item>
                            <item name="label" xsi:type="string" translate="true">Position</item>
                            <item name="dataScope" xsi:type="string">position</item>
                            <item name="visible" xsi:type="boolean">false</item>
                        </item>
                    </argument>
                </field>
                <actionDelete>
                    <argument name="data" xsi:type="array">
                        <item name="config" xsi:type="array">
                            <item name="componentType" xsi:type="string">actionDelete</item>
                            <item name="dataType" xsi:type="string">text</item>
                            <item name="fit" xsi:type="boolean">false</item>
                            <item name="label" xsi:type="string">Actions</item>
                            <item name="additionalClasses" xsi:type="string">data-grid-actions-cell</item>
                            <item name="template" xsi:type="string">Magento_Backend/dynamic-rows/cells/action-delete
                            </item>
                        </item>
                    </argument>
                </actionDelete>
            </container>
        </container>
    </fieldset>
</form>

Now the product edit form showing like this.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.