In magento 2 how to add custom options in action apply field in cart price rule form in admin
This Dropdown options render from getMetadataValues() function which is available in Magento\SalesRule\Model\Rule\Metadata\ValueProvider.php
So, You can create plugin for that because, it's public method. I created plugin for that and get output as like you want.
Follow this below steps for that :
1) Create di.xml to set plugin at app/code/RH/CustomPlugin/etc/adminhtml
:
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<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="salesrule-plugin" type="RH\CustomPlugin\Plugin\Rule\Metadata\ValueProvider" sortOrder="1" />
</type>
</config>
2) Now, create plugin file ValueProvider.php for add custom option for dropdown at RH\CustomPlugin\Plugin\Rule\Metadata
:
<?php
namespace RH\CustomPlugin\Plugin\Rule\Metadata;
class ValueProvider {
public function afterGetMetadataValues(
\Magento\SalesRule\Model\Rule\Metadata\ValueProvider $subject,
$result
) {
$applyOptions = [
'label' => __('Popular'),
'value' => [
[
'label' => 'The Cheapest, also for Buy 1 get 1 free',
'value' => 'buy-1-get-1-free',
],
[
'label' => 'Get $Y for each $X spent',
'value' => 'get-y-for-each-x-spent',
],
],
];
array_push($result['actions']['children']['simple_action']['arguments']['data']['config']['options'], $applyOptions);
return $result;
}
}
Output :
You can modify option in array as you want.
Hope, it will helpful for you.