Hello Magento Friends,
Today’s guide is about How to Add Custom Field in Catalog Price Rule Form in Magento 2?
Catalog price rules are created when merchants want to offer discounts on store products or services. Store owners set rules that must be fulfilled to avail discounts.
Learn – How to Create a Catalog Price Rule in Magento 2
While creating catalog price rules from the Magento 2 backend, the admin needs to apply the required configuration settings. But if you want a custom field in creating catalog price rules, refer to the below steps.
Step 1: Add a custom field in the catalog rule table with db_schema.xml. Navigate to the following path
app/code/Vendor/Extension/etc/db_schema.xml
Now, add the below code
<?xml version="1.0"?> <schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd"> <table name="catalogrule"> <column xsi:type="varchar" name="custom_field" nullable="false" length="255" comment="Custom Field Catalog Price Rule" /> </table> </schema>
Step 2: Create catalog_rule_form.xml file inside ui_component. Go to the below path
app/code/Vendor/Extension/view/adminhtml/ui_component/catalog_rule_form.xml
Then, add the code as follows
<?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" sortOrder="10"> <field name="custom_field" formElement="input"> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> <item name="source" xsi:type="string">sales_rule</item> </item> </argument> <settings> <validation> <rule name="required-entry" xsi:type="boolean">false</rule> </validation> <dataType>text</dataType> <label translate="true">Custom Field</label> <visible>true</visible> <dataScope>custom_field</dataScope> </settings> </field> </fieldset> </form>
Hence, this way you can add any custom field to the catalog price rule form in Magento 2. If you are unable to add a custom field to the catalog price rule, let me know through the comment section. Share the article with your friends and stay updated with us for more solutions.
Happy Coding!
In this guide, we'll explore how to integrate ChatGPT, an AI-powered chatbot, with a Laravel…
In the world of business, understanding financial metrics is crucial for making informed decisions and…
Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…
In this era, businesses are always on the lookout for ways to engage with their…
Managing a Shopify store efficiently involves keeping your product catalog organized. This includes removing outdated…
E-commerce has transformed the way consumers shop for products and services and interact with businesses.…
View Comments
Congratulations on creating such a useful website. Not only is your blog helpful, but it's also incredibly imaginative.
Magnificent and intriguing article. Incredible things you've generally imparted to us. Much appreciated. Simply keep making this sort out of post.