Hello Magento Friends,
Customization is the centerpiece of the Magento framework. In this tutorial, I am going to explain How to Add Custom Options for the Action field of the Cart Price Rule Form in Magento 2.
Cart Price Rules are created when you want to offer any discount to customers. Admin needs to create cart price rules and apply the conditions and actions from the Magento backend.
Note: Track all the activities performed by your admin users by installingĀ Magento 2 Admin Action Log.
Magento 2 provides four default actions for the apply field in the cart price rule.
However, if the default options donāt match your requirements, you can add your custom options too in the actions apply field of cart price rule in Magento 2. Letās check how
Contents
Step 1: Add di.xml file for the plugin in the following file path
app\code\Vendor\Extension\etc\adminhtml
Now, add the code as follows
<?xml version="1.0" encoding="UTF-8"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">Ā <type name="Magento\SalesRule\Model\Rule\Metadata\ValueProvider">Ā <plugin name="salesactionrule-plugin" type="Vendor\Extension\Plugin\Rule\Metadata\Valueprovider" sortOrder="1" />Ā </type>Ā </config>
Step 2: Create plugin file Valueprovider.php in the below file path to add custom option in action field dropdown
app\code\Vendor\Extension\Plugin\Rule\Metadata
Then add the below-mentioned piece of code
<?phpĀ namespace app\code\Vendor\Extension\Plugin\Rule\Metadata;Ā class Valueprovider {Ā public function afterGetMetadataValues(Ā \Magento\SalesRule\Model\Rule\Metadata\ValueProvider $subject,Ā $result ) {Ā $applyOptions = [Ā 'label' => __(Action Title),Ā 'value' => [Ā [ 'label' => 'Action field label 1', 'value' => 'Action field value 1', ],Ā [ 'label' => 'Action field label 2', 'value' => 'Action field value 2', ],Ā ],Ā ];Ā array_push($result['actions']['children']['simple_action']['arguments']['data']['config']['options'], $applyOptions); return $result; } }
Accordingly, you can add custom options to apply field dropdown in the cart price rule actions tab of Magento 2. In case you are unable to add, feel free to reach me through the comments. Share the article with the ones who are in search of cart price rule customization.
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
Do you have guidelines for the implementation of actions? I need your help. Thank you.
For the customization, you need to contact us at https://magecomp.com/contact