4

Is it possible to add additional (simple string) attribute to the Catalog Price Rule? If it is, please, tell about it in details. Better with working code example.

[UPD]

I mean add attribute to the price rule itself.

enter image description here

7

It is pretty easy to do this in Magento 2.1. You need to add a row to the catalogrule table using the module (in your own module):

app/code/Vendor/Rules/Setup/InstallSchema.php

namespace Vendor\Rules\Setup;

use Magento\Framework\Setup\InstallSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;

class InstallSchema implements InstallSchemaInterface
{

    public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
    {
        $installer = $setup;
        $installer->startSetup();

        $installer->getConnection()->addColumn(
            $installer->getTable('catalogrule'),
            'test_column',
            [
                'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                'length' => 32,
                'nullable' => false,
                'default' => '',
                'comment' => 'Test Column'
            ]
        );

        $installer->endSetup();
    }
}

Then, add a UI form update to the catalog rule form in your module:

app/code/Vendor/Rules/view/adminhtml/ui_component/catalog_rule_form.xml

<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <fieldset name="rule_information">
        <field name="test_column">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="label" xsi:type="string">Test Column</item>
                    <item name="visible" xsi:type="boolean">true</item>
                    <item name="dataType" xsi:type="string">text</item>
                    <item name="formElement" xsi:type="string">input</item>
                    <item name="source" xsi:type="string">catalog_rule</item>
                    <item name="dataScope" xsi:type="string">test_column</item>
                    <item name="sortOrder" xsi:type="number">50</item>
                    <item name="validation" xsi:type="array">
                        <item name="required-entry" xsi:type="boolean">true</item>
                    </item>
                </item>
            </argument>
        </field>
    </fieldset>
</form>

The result will be the following:

enter image description here

Data save will be working on default:

enter image description here

You can add your own fieldset with fields in the same way.

  • Yes, I did it, but Image uploader not working. Text works, but image uploader...not. – D.R. Oct 7 '16 at 10:38
  • @D.R. You wrote: Is it possible to add additional (simple string) attribute to the Catalog Price Rule If you face the problem with the file input type, then, please, accept this answer and create a new topic to not mislead those who will come from Google. We'll try to help you. – MageWorx Oct 7 '16 at 12:56
  • oh, you are right. Thanks. Of course, I will. Just have no sleep for a long time) – D.R. Oct 7 '16 at 13:21
  • here is the link magento.stackexchange.com/questions/139897/… – D.R. Oct 7 '16 at 13:38
1

yes its Possible

GO to Store => Attributes => product

Then Select attribute that you want to show in Catalog Price Rule

Let say example i selected Color => Go to Storefront Properties & then select Use for Promo Rule Conditions => Yes & save

Run the below Command

php bin/magento cache:flush

Check now on catalog Price Rule

  • Thank you for the answer, but I mean add attribute to the price rule itself. – D.R. Oct 5 '16 at 6:56
0

You can copy entire catalog_rule_form.xml to your ui_component, clean cache and done.

Here is my file path magento2-root/src/app/code/Love/OneRoom/view/adminhtml/ui_component/catalog_rule_form.xml

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.