How to Add Rule Condition Field in Magento 2 Admin UI Component Form
The default Magento 2 offers the rule tree condition field using which the admin can configure the condition-based features.
For example, the admin may want to offer a discount coupon only on certain products or specific customer groups.
As online stores grow complex, the condition-based features are used more. Additionally, if you are customizing your own features for a better shopping platform, you may need to add rule condition field in Magento 2 admin UI component form as shown below.
You can do so with the below code.
Method to Add Rule Condition Field in Magento 2 Admin UI Component Form:
Create [Vendor]/[Module]/view/adminhtml/layout/route_controller_grid.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<fieldset name="conditions"> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> <item name="label" xsi:type="string" translate="true">Conditions</item> <item name="collapsible" xsi:type="boolean">true</item> <item name="sortOrder" xsi:type="number">10</item> </item> </argument> <container name="conditions" > <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> <item name="sortOrder" xsi:type="number">10</item> </item> </argument> <htmlContent name="html_content"> <argument name="block" xsi:type="object">Magento\SalesRule\Block\Adminhtml\Promo\Quote\Edit\Tab\Conditions</argument> </htmlContent> </container> </fieldset> |
That’s it. Also you can Magento 2 custom attribute validation rule using ruleFactory enhances e-commerce customization and efficiency, allowing dynamic promotions and improving the user experience.
Also read: How to Validate Condition Rules in Custom Module in Magento 2.
Any doubts about the above solution? If so, do not hesitate to mention them in the Comments section below.
I’d be happy to help.
Also, do share the solution with Magento Community via social media.
Thank you.
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
Prev
How to Add Hyperlink in PDF File in Magento 2
How to Integrate Facebook Shop with Magento 2 [2024]
Next