0

I need to save values of two custom fields which I have added using xml. Below is the xml in which I have added that fields also they reflect in cart price rule form.

 <fieldset name="custom details">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="label" xsi:type="string" translate="true"> Detail1</item>
            <item name="collapsible" xsi:type="boolean">true</item>
            <item name="sortOrder" xsi:type="string">40</item>
        </item>
    </argument>
    <field name="field1">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="label" xsi:type="string" translate="true">i</item>
                <item name="dataType" xsi:type="string">text</item>
                <item name="formElement" xsi:type="string">input</item>
                <item name="source" xsi:type="string">sales_rule</item>
                <item name="dataScope" xsi:type="string">field1</item>
                <item name="validation" xsi:type="array">
                    <item name="required-entry" xsi:type="boolean">true</item>
                </item>
            </item>
        </argument>
    </field>
    <field name="field2">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="dataType" xsi:type="string">text</item>
                <item name="formElement" xsi:type="string">wysiwyg</item>
                <item name="source" xsi:type="string">sales_rule</item>
                <item name="label" xsi:type="string">Field2</item>

                <item name="template" xsi:type="string">ui/form/field</item>
                <item name="wysiwyg" xsi:type="boolean">true</item>
                <item name="dataScope" xsi:type="string">terms_conditions</item>
                <item name="sortOrder" xsi:type="number">50</item>
                <!--<item name="rows" xsi:type="number">8</item>-->
                <item name="validation" xsi:type="array">
                    <item name="required-entry" xsi:type="boolean">true</item>
                </item>

            </item>
        </argument>
    </field>
</fieldset>

I am struggling as on how shall I save the values of two fields in the database against their database field columns.I tried to go through save.php in Namespace/Modulename/Controller/Adminhtml/Promo/Quote/Save.But could find any success in that. Can someone please help.

1

You don't need to write custom Model for that, If you add custom field using ui_component than it will save automatically to the DB.

You need to create relative field to salesrule table.

Create setup file at below path.

Vendor/Module/Setup/InstallData.php

public function install(
    ModuleDataSetupInterface $setup,
    ModuleContextInterface $context
) {
    $setup->startSetup();

     $setup->getConnection()->addColumn(
        $setup->getTable('salesrule'),
        'group_members',
        [
            'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
            'length' => 32,
            'nullable' => false,
            'default' => '',
            'comment' => 'Group Members'
        ]
    );

Than Run below commands from Magento root.

php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy
php bin/magento cache:clean

Note: If you modifying existing Module setup file than you must need to remove your module entry from setup table.

Hope it will help you !!

  • Done..I had set type as integer for database fields due to which it was not saving in database. – Nisith Mar 27 '18 at 5:11
  • If solution worked for you than accept answer that will help community. – anonymous Mar 27 '18 at 5:30

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.