Before you begin
You need the following:- The id of the rate to change, such as
comrate_01JD8Q1234567 - The ids of the rules to update or delete, from the rate’s
rulesrelation
1
Look up the rate's rules
List the rate’s current rules through the module service.Each rule has an
id, a reference, and a reference_id. You need the id to update or delete a rule.2
Run the batch
Call The result is
batchCommissionRulesWorkflow from an API route. This route adds a seller rule, retargets a category rule, and removes a product rule.src/api/admin/commission-scopes/route.ts
{ created, updated, deleted }: the created and updated rules, and the deleted ids.How the three operations run
The workflow runscreateCommissionRulesStep, updateCommissionRulesStep, and deleteCommissionRulesStep in parallel. Each array is optional, and an empty or missing one is a no-op. If any step fails, the others roll back: created rules are deleted, updated rules get their old values, and deleted rules are created again.
A rolled-back delete creates new rule records with the same
reference and reference_id. The rules keep their meaning, but their ids change.How the new rules change matching
Adding rules narrows a rate. Rules on the same dimension are alternatives, and rules on different dimensions must all match. Adding theseller rule above to a rate that already had a product_category rule raises its specificity from 1 to 2, so it now beats single-dimension rates on that seller’s lines in that category.
Use only the five supported references: product, product_type, product_collection, product_category, and seller. The module stores any string, and a rule with an unknown reference makes the rate match nothing.
Recompute existing orders
Rule changes affect orders placed or refreshed after the change. To apply new rules to existing orders, runrefreshOrderCommissionLinesWorkflow for them.