Each dimension checks one product field
A rule compares itsreference_id with one field of the line’s product. The product comes from the order line, and the seller comes from the offer the customer bought.
Products are a shared catalog that no seller owns, which is why the
seller dimension reads the offer on the line and not the product.
AND across dimensions, OR within one
Mercur groups a rate’s rules byreference. The rate matches a line when every group has at least one rule that matches. Rules in the same group are alternatives, and groups narrow each other.
The most specific rate wins
When several rates match, Mercur sorts them by specificity and keeps the first. Specificity is the number of distinct dimensions a rate’s rules use, not the number of rules. The rules above give a specificity of 2. Mercur resolves each line in this order:- Drop disabled rates and rates whose
currency_codeis set to another currency. - Keep the rates that match the line. A rate without rules always matches.
- Sort by specificity, highest first.
- Break ties by
created_at, oldest first. - Apply the first rate to the line’s base amount.
Shipping uses the global rate only
Shipping methods aren’t matched against rules. If the global rate hasinclude_shipping set, every shipping method on the order gets a line from it, with the description Shipping Commission. Otherwise shipping isn’t commissioned.
The global rate’s include_tax flag applies to shipping too, adding the method’s tax_total to its subtotal. For a fixed global rate, each shipping method gets the fixed amount.
Rates load once per batch
Thesystem provider loads all enabled rates with their rules and values in one query per batch of orders. It then resolves every line of every order in memory. Adding rates doesn’t add queries per line.