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.
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityIs 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.
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:
Data save will be working on default:
You can add your own fieldset with fields in the same way.
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
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