Magento2 Magento 2-目录规则的自定义操作

Magento2 Magento 2-目录规则的自定义操作,magento2,Magento2,我需要为目录价格规则创建自定义操作。不是整个自定义的目录规则,而是我可以选择的操作。此操作的目的只是根据一些标准重新计算产品价格 我怎样才能做到呢 要达到您的要求,请尝试以下步骤 在自定义模块中,覆盖目录\u规则\u表单.xml 在catalog\u rule\u form.xml中查找以下字段集 在上述操作字段集中,您可以找到预定义的现有规则,然后添加自定义规则,如下所示 <rule name="4"> <value>custom_action</val

我需要为
目录价格规则
创建自定义操作。不是整个自定义的
目录规则
,而是我可以选择的操作。此操作的目的只是根据一些标准重新计算产品价格

我怎样才能做到呢


要达到您的要求,请尝试以下步骤

在自定义模块中,覆盖
目录\u规则\u表单.xml

catalog\u rule\u form.xml中查找以下字段集

在上述操作字段集中,您可以找到预定义的现有规则,然后添加自定义规则,如下所示

<rule name="4">
    <value>custom_action</value>
    <actions>
        <action name="0">
        <target>catalog_rule_form.catalog_rule_form
        .actions.discount_amount</target>
            <callback>setValidation</callback>
            <params>
                <param name="0" xsi:type="string">validate-number-range</param>
                <param name="1" xsi:type="string">false</param>
            </params>
        </action>
    </actions>
</rule>
Magento\CatalogRule\Model\Rule\Action\SimpleActionOptionsProvider.php

<?php
namespace Magento\CatalogRule\Model\Rule\Action;

class SimpleActionOptionsProvider implements 
\Magento\Framework\Data\OptionSourceInterface
{
    /**
      * @return array
     */
    public function toOptionArray()
    {
        return [
        [
            'label' => __('Apply as percentage of original'),
            'value' => 'by_percent'
        ],
        [
            'label' => __('Apply as fixed amount'),
            'value' => 'by_fixed'
        ],
        [
            'label' => __('Adjust final price to this percentage'),
            'value' => 'to_percent'
        ],
        [
            'label' => __('Adjust final price to discount value'),
            'value' => 'to_fixed'
        ],
        [
            'label' => __('Custom Action'),
            'value' => 'custom_action'
        ]
    ];
    }
}
[enter image description here][1]

[1]: https://i.stack.imgur.com/EjG19.png