Skip to content

Create after save plugin on the purchase order rule repository magento 2

I have added new column via db_schema.xml in the purchase_order_rule table i.e. rule_type
Now, I want to create an after save plugin on the purchase order rule repository that will save the column ‘conditions_serialized’ attribute value to the ‘rule_type’ column.

Data that I want to save –
In the ‘conditions_serialized’ column we have data in the purchase-order_rule table in the format –

{“type”: “MagentoPurchaseOrderRuleModelRuleConditionCombine”,”attribute”:null,”operator”:null,”value”:”1″,”is_value_processed”:null,”aggregator”:”all”,”conditions”:[{“type”:”MagentoPurchaseOrderRuleModelRuleConditionAddress”,”attribute”:”grand_total”,”operator”:”>”,”value”:”1000″,”is_value_processed”:false,”currency_code”:”USD”}]}

But I want to save the ‘attribute’ label in the new column ‘rule_type’ column i.e. We have HTML as

<select name="conditions[0][attribute]" id="condition_attribute" class="select required-entry" title="Rule type" aria-required="true">
                <option value="">Please select</option>
                                                                <option value="grand_total">Order Total</option>
                                                            <option value="shipping_incl_tax">Shipping Cost</option>
                                                            <option value="number_of_skus">Number of SKUs</option>
                            </select>

Suppose, across the attribute ‘grand_total’ I want to save ‘Order Total’ in the ‘rule_type’ column

Can someone suggest me how to do tht via repository only?