@mercurjs/docs 2.2.1 → 2.3.0-canary.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/content/home.mdx +107 -0
- package/content/learn/architecture.mdx +168 -83
- package/content/learn/introduction.mdx +161 -56
- package/content/learn/migration-to-2-0.mdx +187 -0
- package/content/learn/why-mercur.mdx +91 -0
- package/content/platform/attribute/concepts/attribute-types.mdx +59 -0
- package/content/platform/attribute/concepts/global-vs-inline.mdx +50 -0
- package/content/platform/attribute/concepts/variant-axes.mdx +61 -0
- package/content/platform/attribute/guides/attach-attributes-to-a-product.mdx +69 -0
- package/content/platform/attribute/guides/create-a-variant-axis.mdx +83 -0
- package/content/platform/attribute/guides/create-an-attribute.mdx +81 -0
- package/content/platform/attribute/overview.mdx +87 -0
- package/content/platform/attribute/reference/data-models.mdx +56 -0
- package/content/platform/attribute/reference/events.mdx +41 -0
- package/content/platform/attribute/reference/links.mdx +45 -0
- package/content/platform/attribute/reference/service.mdx +49 -0
- package/content/platform/attribute/reference/workflows.mdx +45 -0
- package/content/platform/catalog/concepts/master-products.mdx +54 -0
- package/content/platform/catalog/concepts/product-seller-allowlist.mdx +48 -0
- package/content/platform/catalog/concepts/status-lifecycle.mdx +58 -0
- package/content/platform/catalog/concepts/variants-categories-collections.mdx +49 -0
- package/content/platform/catalog/guides/allowlist-stores.mdx +59 -0
- package/content/platform/catalog/guides/create-a-master-product.mdx +70 -0
- package/content/platform/catalog/guides/publish-or-reject-a-product.mdx +79 -0
- package/content/platform/catalog/overview.mdx +90 -0
- package/content/platform/catalog/reference/data-models.mdx +66 -0
- package/content/platform/catalog/reference/events.mdx +41 -0
- package/content/platform/catalog/reference/links.mdx +44 -0
- package/content/platform/catalog/reference/service.mdx +52 -0
- package/content/platform/catalog/reference/workflows.mdx +40 -0
- package/content/platform/commission/concepts/order-commission-lines.mdx +65 -0
- package/content/platform/commission/concepts/rule-matching.mdx +86 -0
- package/content/platform/commission/concepts/rules-and-rates.mdx +84 -0
- package/content/platform/commission/guides/batch-update-rules.mdx +58 -0
- package/content/platform/commission/guides/create-a-rate.mdx +72 -0
- package/content/platform/commission/guides/refresh-order-commission-lines.mdx +55 -0
- package/content/platform/commission/overview.mdx +86 -0
- package/content/platform/commission/reference/data-models.mdx +75 -0
- package/content/platform/commission/reference/events.mdx +58 -0
- package/content/platform/commission/reference/links.mdx +45 -0
- package/content/platform/commission/reference/service.mdx +51 -0
- package/content/platform/commission/reference/workflows.mdx +40 -0
- package/content/platform/offer/concepts/pricing-and-inventory.mdx +72 -0
- package/content/platform/offer/concepts/shipping.mdx +48 -0
- package/content/platform/offer/concepts/what-is-an-offer.mdx +65 -0
- package/content/platform/offer/guides/bulk-create-offers.mdx +84 -0
- package/content/platform/offer/guides/create-an-offer.mdx +83 -0
- package/content/platform/offer/guides/manage-offer-inventory.mdx +53 -0
- package/content/platform/offer/overview.mdx +84 -0
- package/content/platform/offer/reference/data-models.mdx +56 -0
- package/content/platform/offer/reference/events.mdx +39 -0
- package/content/platform/offer/reference/links.mdx +60 -0
- package/content/platform/offer/reference/service.mdx +53 -0
- package/content/platform/offer/reference/workflows.mdx +38 -0
- package/content/platform/order-group/concepts/computed-totals.mdx +59 -0
- package/content/platform/order-group/concepts/order-splitting.mdx +61 -0
- package/content/platform/order-group/concepts/the-order-group.mdx +64 -0
- package/content/platform/order-group/guides/list-order-groups.mdx +67 -0
- package/content/platform/order-group/guides/retrieve-an-order-group.mdx +63 -0
- package/content/platform/order-group/guides/split-a-cart.mdx +58 -0
- package/content/platform/order-group/overview.mdx +83 -0
- package/content/platform/order-group/reference/data-models.mdx +40 -0
- package/content/platform/order-group/reference/events.mdx +37 -0
- package/content/platform/order-group/reference/links.mdx +45 -0
- package/content/platform/order-group/reference/service.mdx +50 -0
- package/content/platform/order-group/reference/workflows.mdx +39 -0
- package/content/platform/payout/concepts/account-lifecycle.mdx +75 -0
- package/content/platform/payout/concepts/accounts-and-onboarding.mdx +70 -0
- package/content/platform/payout/concepts/payout-pipeline.mdx +99 -0
- package/content/platform/payout/guides/create-a-payout-account.mdx +59 -0
- package/content/platform/payout/guides/process-a-provider-webhook.mdx +74 -0
- package/content/platform/payout/guides/start-provider-onboarding.mdx +50 -0
- package/content/platform/payout/overview.mdx +86 -0
- package/content/platform/payout/reference/data-models.mdx +61 -0
- package/content/platform/payout/reference/events.mdx +48 -0
- package/content/platform/payout/reference/links.mdx +36 -0
- package/content/platform/payout/reference/service.mdx +53 -0
- package/content/platform/payout/reference/workflows.mdx +32 -0
- package/content/platform/product-edit/concepts/change-actions.mdx +66 -0
- package/content/platform/product-edit/concepts/change-pipeline.mdx +69 -0
- package/content/platform/product-edit/concepts/status-and-auto-confirm.mdx +66 -0
- package/content/platform/product-edit/guides/confirm-or-decline-a-change.mdx +76 -0
- package/content/platform/product-edit/guides/edit-a-product.mdx +74 -0
- package/content/platform/product-edit/guides/request-a-revision.mdx +54 -0
- package/content/platform/product-edit/overview.mdx +85 -0
- package/content/platform/product-edit/reference/data-models.mdx +65 -0
- package/content/platform/product-edit/reference/events.mdx +47 -0
- package/content/platform/product-edit/reference/links.mdx +39 -0
- package/content/platform/product-edit/reference/service.mdx +43 -0
- package/content/platform/product-edit/reference/workflows.mdx +49 -0
- package/content/platform/review/concepts/product-vs-seller-reviews.mdx +63 -0
- package/content/platform/review/concepts/ratings-and-moderation.mdx +64 -0
- package/content/platform/review/concepts/the-review-model.mdx +56 -0
- package/content/platform/review/guides/compute-aggregate-ratings.mdx +57 -0
- package/content/platform/review/guides/create-a-review.mdx +55 -0
- package/content/platform/review/guides/moderate-a-review.mdx +58 -0
- package/content/platform/review/guides/respond-to-a-review.mdx +61 -0
- package/content/platform/review/overview.mdx +87 -0
- package/content/platform/review/reference/data-models.mdx +36 -0
- package/content/platform/review/reference/events.mdx +61 -0
- package/content/platform/review/reference/links.mdx +43 -0
- package/content/platform/review/reference/service.mdx +54 -0
- package/content/platform/review/reference/workflows.mdx +31 -0
- package/content/platform/store/concepts/lifecycle.mdx +62 -0
- package/content/platform/store/concepts/store-entity.mdx +53 -0
- package/content/platform/store/concepts/team.mdx +50 -0
- package/content/platform/store/guides/create-a-store.mdx +55 -0
- package/content/platform/store/guides/manage-the-team.mdx +55 -0
- package/content/platform/store/guides/moderate-a-store.mdx +59 -0
- package/content/platform/store/overview.mdx +86 -0
- package/content/platform/store/reference/data-models.mdx +89 -0
- package/content/platform/store/reference/events.mdx +43 -0
- package/content/platform/store/reference/links.mdx +71 -0
- package/content/platform/store/reference/service.mdx +51 -0
- package/content/platform/store/reference/workflows.mdx +35 -0
- package/content/references/api/admin/commission-rates/create-commission-rate.mdx +1 -1
- package/content/references/api/admin/commission-rates/list-commission-rates.mdx +2 -2
- package/content/references/api/admin/commission-rates/update-commission-rate.mdx +1 -1
- package/content/references/api/admin/offers/batch-create-offers.mdx +3 -3
- package/content/references/api/admin/order-groups/list-order-groups.mdx +1 -1
- package/content/references/api/admin/product-attributes/create-attribute-value.mdx +2 -2
- package/content/references/api/admin/product-attributes/create-product-attribute.mdx +1 -1
- package/content/references/api/admin/product-attributes/update-product-attribute.mdx +1 -1
- package/content/references/api/admin/product-changes/confirm-product-change.mdx +1 -1
- package/content/references/api/admin/products/batch-product-attributes.mdx +1 -1
- package/content/references/api/admin/products/create-product.mdx +1 -1
- package/content/references/api/admin/products/preview-product.mdx +1 -1
- package/content/references/api/admin.mdx +4 -5
- package/content/references/api/conventions.mdx +9 -7
- package/content/references/api/store/carts/add-line-item.mdx +1 -1
- package/content/references/api/store/offers/list-offers.mdx +1 -1
- package/content/references/api/store/order-groups/list-order-groups.mdx +1 -1
- package/content/references/api/store.mdx +4 -13
- package/content/references/api/vendor/members/accept-member-invite.mdx +1 -1
- package/content/references/api/vendor/offers/batch-create-offers.mdx +4 -0
- package/content/references/api/vendor/offers/batch-offer-inventory-items.mdx +2 -0
- package/content/references/api/vendor/offers/create-offer.mdx +13 -1
- package/content/references/api/vendor/offers/list-offers.mdx +4 -0
- package/content/references/api/vendor/offers/retrieve-offer.mdx +4 -0
- package/content/references/api/vendor/offers/update-offer.mdx +12 -0
- package/content/references/api/vendor/payout-accounts/create-onboarding.mdx +1 -1
- package/content/references/api/vendor/products/batch-product-attributes.mdx +1 -1
- package/content/references/api/vendor/products/create-product-variant.mdx +1 -1
- package/content/references/api/vendor/products/create-product.mdx +1 -1
- package/content/references/api/vendor/products/delete-product.mdx +1 -1
- package/content/references/api/vendor/products/update-product.mdx +1 -1
- package/content/references/api/vendor/sellers/create-seller.mdx +2 -2
- package/content/references/api/vendor/sellers/list-sellers.mdx +1 -1
- package/content/references/api/vendor.mdx +6 -5
- package/content/references/configuration.mdx +16 -33
- package/content/references/overview.mdx +34 -52
- package/content/references/panel-extensions/create-page.mdx +194 -0
- package/content/references/panel-extensions/custom-fields.mdx +256 -0
- package/content/references/panel-extensions/overview.mdx +102 -0
- package/content/references/panel-extensions/widgets.mdx +212 -0
- package/content/resources/ai/mcp.mdx +2 -2
- package/content/resources/ai/overview.mdx +21 -16
- package/content/resources/ai/skills.mdx +67 -0
- package/content/resources/best-practices/api-routes.mdx +55 -43
- package/content/resources/best-practices/custom-fields.mdx +116 -92
- package/content/resources/best-practices/frontend.mdx +62 -50
- package/content/resources/best-practices/module-links.mdx +48 -34
- package/content/resources/best-practices/modules.mdx +53 -27
- package/content/resources/best-practices/overview.mdx +45 -17
- package/content/resources/best-practices/subscribers-and-jobs.mdx +37 -24
- package/content/resources/best-practices/types.mdx +38 -23
- package/content/resources/best-practices/workflows.mdx +33 -21
- package/content/resources/customization/custom-fields.mdx +15 -15
- package/content/resources/customization/extend-a-workflow.mdx +7 -4
- package/content/resources/customization/extending-panels.mdx +55 -52
- package/content/resources/deployment/medusa-cloud.mdx +21 -20
- package/content/resources/deployment/self-host.mdx +123 -0
- package/content/resources/integrations/overview.mdx +38 -0
- package/content/resources/integrations/stripe-connect.mdx +39 -38
- package/content/resources/tutorials/add-a-block.mdx +25 -18
- package/content/resources/tutorials/add-a-widget.mdx +32 -23
- package/content/resources/tutorials/add-order-detail-button.mdx +33 -20
- package/content/resources/tutorials/attributes-and-variant-axes.mdx +28 -27
- package/content/resources/tutorials/build-a-block.mdx +26 -15
- package/content/resources/tutorials/custom-api-route.mdx +32 -20
- package/content/resources/tutorials/custom-panel-page.mdx +21 -12
- package/content/resources/tutorials/customize-navigation.mdx +30 -23
- package/content/resources/tutorials/extend-forms-and-tables.mdx +36 -28
- package/content/resources/tutorials/extend-onboarding.mdx +38 -35
- package/content/resources/tutorials/master-products-and-offers.mdx +28 -23
- package/content/telemetry.mdx +3 -3
- package/content/user-guide/admin/attributes/how-tos/create-an-attribute.mdx +64 -0
- package/content/user-guide/admin/attributes/how-tos/manage-possible-values.mdx +40 -0
- package/content/user-guide/admin/attributes/overview.mdx +22 -0
- package/content/user-guide/admin/commissions/how-tos/create-a-commission-rule.mdx +63 -0
- package/content/user-guide/admin/commissions/how-tos/edit-the-global-commission.mdx +48 -0
- package/content/user-guide/admin/commissions/how-tos/manage-a-commission-rule.mdx +45 -0
- package/content/user-guide/admin/commissions/overview.mdx +25 -0
- package/content/user-guide/admin/overview.mdx +20 -12
- package/content/user-guide/admin/product-requests/how-tos/review-a-new-product.mdx +58 -0
- package/content/user-guide/admin/product-requests/how-tos/review-a-product-edit.mdx +48 -0
- package/content/user-guide/admin/product-requests/overview.mdx +25 -0
- package/content/user-guide/vendor/offers/how-tos/create-an-offer.mdx +59 -0
- package/content/user-guide/vendor/offers/how-tos/update-prices-and-stock.mdx +40 -0
- package/content/user-guide/vendor/offers/overview.mdx +22 -0
- package/content/user-guide/vendor/onboarding.mdx +79 -0
- package/content/user-guide/vendor/orders/how-tos/fulfill-an-order.mdx +49 -0
- package/content/user-guide/vendor/orders/how-tos/mark-an-order-as-delivered.mdx +33 -0
- package/content/user-guide/vendor/orders/how-tos/process-a-return.mdx +42 -0
- package/content/user-guide/vendor/orders/how-tos/refund-an-order.mdx +38 -0
- package/content/user-guide/vendor/orders/how-tos/ship-an-order.mdx +40 -0
- package/content/user-guide/vendor/orders/overview.mdx +31 -0
- package/content/user-guide/vendor/overview.mdx +23 -12
- package/content/user-guide/vendor/products/how-tos/edit-a-product.mdx +44 -0
- package/content/user-guide/vendor/products/how-tos/submit-a-product.mdx +63 -0
- package/content/user-guide/vendor/products/overview.mdx +22 -0
- package/llms.txt +176 -142
- package/package.json +1 -1
- package/content/learn/concepts.mdx +0 -84
- package/content/learn/installation.mdx +0 -117
- package/content/learn/mirakl-alternative.mdx +0 -86
- package/content/migration/from-1-x-to-2-0.mdx +0 -152
- package/content/migration/from-2-0-to-2-1.mdx +0 -105
- package/content/migration/overview.mdx +0 -58
- package/content/references/api/store/search/search.mdx +0 -136
- package/content/references/modules/commission.mdx +0 -106
- package/content/references/modules/custom-fields.mdx +0 -45
- package/content/references/modules/media.mdx +0 -55
- package/content/references/modules/offer.mdx +0 -64
- package/content/references/modules/payout.mdx +0 -121
- package/content/references/modules/product-attribute.mdx +0 -111
- package/content/references/modules/product-edit.mdx +0 -80
- package/content/references/modules/search.mdx +0 -112
- package/content/references/modules/seller.mdx +0 -175
- package/content/references/panel-extension-api.mdx +0 -337
- package/content/references/workflows/cart/add-seller-shipping-method-to-cart.mdx +0 -48
- package/content/references/workflows/cart/complete-cart-with-split-orders.mdx +0 -36
- package/content/references/workflows/cart/list-seller-shipping-options-for-cart.mdx +0 -39
- package/content/references/workflows/cart/update-cart-seller-promotions.mdx +0 -42
- package/content/references/workflows/commission/batch-commission-rules.mdx +0 -49
- package/content/references/workflows/commission/create-commission-rates.mdx +0 -41
- package/content/references/workflows/commission/delete-commission-rates.mdx +0 -34
- package/content/references/workflows/commission/refresh-order-commission-lines.mdx +0 -30
- package/content/references/workflows/commission/update-commission-rates.mdx +0 -35
- package/content/references/workflows/media/set-category-images.mdx +0 -41
- package/content/references/workflows/media/set-collection-images.mdx +0 -41
- package/content/references/workflows/member/accept-member-invite.mdx +0 -33
- package/content/references/workflows/member/add-seller-member.mdx +0 -30
- package/content/references/workflows/member/create-member-invites.mdx +0 -34
- package/content/references/workflows/member/delete-member-invite.mdx +0 -24
- package/content/references/workflows/member/remove-seller-member.mdx +0 -28
- package/content/references/workflows/member/resend-member-invite.mdx +0 -28
- package/content/references/workflows/member/update-member-role.mdx +0 -28
- package/content/references/workflows/member/update-member.mdx +0 -35
- package/content/references/workflows/offer/batch-offer-inventory-items.mdx +0 -62
- package/content/references/workflows/offer/create-offers.mdx +0 -65
- package/content/references/workflows/offer/delete-offers.mdx +0 -35
- package/content/references/workflows/offer/update-offers.mdx +0 -53
- package/content/references/workflows/order/cancel-order-fulfillment.mdx +0 -34
- package/content/references/workflows/order/confirm-claim-request.mdx +0 -25
- package/content/references/workflows/order/confirm-exchange-request.mdx +0 -25
- package/content/references/workflows/order/confirm-order-edit-request.mdx +0 -25
- package/content/references/workflows/order/confirm-return-receive.mdx +0 -25
- package/content/references/workflows/order/create-order-fulfillment.mdx +0 -45
- package/content/references/workflows/order-group/get-order-group-detail.mdx +0 -29
- package/content/references/workflows/order-group/get-order-groups-list.mdx +0 -38
- package/content/references/workflows/overview.mdx +0 -72
- package/content/references/workflows/payout/create-onboarding.mdx +0 -36
- package/content/references/workflows/payout/create-payout-account.mdx +0 -33
- package/content/references/workflows/payout/create-payout.mdx +0 -30
- package/content/references/workflows/payout/process-payout-for-webhook.mdx +0 -34
- package/content/references/workflows/product/confirm-products.mdx +0 -48
- package/content/references/workflows/product/create-products.mdx +0 -63
- package/content/references/workflows/product/link-sellers-to-product-category.mdx +0 -40
- package/content/references/workflows/product/link-sellers-to-product.mdx +0 -40
- package/content/references/workflows/product/reject-product.mdx +0 -48
- package/content/references/workflows/product/request-product-change.mdx +0 -48
- package/content/references/workflows/product-attribute/add-product-attributes-to-product.mdx +0 -49
- package/content/references/workflows/product-attribute/create-and-link-product-attributes-to-product.mdx +0 -46
- package/content/references/workflows/product-attribute/create-product-attribute-values.mdx +0 -43
- package/content/references/workflows/product-attribute/create-product-attributes.mdx +0 -56
- package/content/references/workflows/product-attribute/delete-product-attribute-values.mdx +0 -30
- package/content/references/workflows/product-attribute/delete-product-attributes.mdx +0 -30
- package/content/references/workflows/product-attribute/remove-product-attributes-from-product.mdx +0 -29
- package/content/references/workflows/product-attribute/update-product-attribute-values.mdx +0 -44
- package/content/references/workflows/product-attribute/update-product-attributes-on-product.mdx +0 -41
- package/content/references/workflows/product-attribute/update-product-attributes.mdx +0 -48
- package/content/references/workflows/product-attribute/upsert-product-attribute-values.mdx +0 -43
- package/content/references/workflows/product-edit/auto-confirm-product-change.mdx +0 -39
- package/content/references/workflows/product-edit/cancel-product-change.mdx +0 -49
- package/content/references/workflows/product-edit/confirm-product-change.mdx +0 -57
- package/content/references/workflows/product-edit/create-product-change.mdx +0 -72
- package/content/references/workflows/product-edit/reject-product-change.mdx +0 -54
- package/content/references/workflows/product-edit/stage-product-change.mdx +0 -75
- package/content/references/workflows/seller/approve-seller.mdx +0 -36
- package/content/references/workflows/seller/create-seller-account.mdx +0 -59
- package/content/references/workflows/seller/create-seller-defaults.mdx +0 -22
- package/content/references/workflows/seller/create-sellers.mdx +0 -65
- package/content/references/workflows/seller/delete-seller-professional-details.mdx +0 -37
- package/content/references/workflows/seller/delete-sellers.mdx +0 -24
- package/content/references/workflows/seller/invite-seller.mdx +0 -28
- package/content/references/workflows/seller/suspend-seller.mdx +0 -37
- package/content/references/workflows/seller/terminate-seller.mdx +0 -37
- package/content/references/workflows/seller/unsuspend-seller.mdx +0 -36
- package/content/references/workflows/seller/unterminate-seller.mdx +0 -36
- package/content/references/workflows/seller/update-seller-address.mdx +0 -55
- package/content/references/workflows/seller/update-seller-payment-details.mdx +0 -52
- package/content/references/workflows/seller/update-seller-professional-details.mdx +0 -48
- package/content/references/workflows/seller/update-sellers.mdx +0 -57
- package/content/resources/ai/llms.mdx +0 -74
- package/content/resources/integrations/notifications.mdx +0 -39
- package/content/resources/integrations/search.mdx +0 -122
- package/content/resources/tutorials/configure-commissions.mdx +0 -127
- package/content/resources/tutorials/first-marketplace.mdx +0 -45
- package/content/resources/tutorials/handle-product-requests.mdx +0 -80
- package/content/resources/tutorials/import-export-products.mdx +0 -96
- package/content/resources/tutorials/seller-payouts-stripe.mdx +0 -89
- package/content/resources/tutorials/store-setup-checklist.mdx +0 -214
- package/content/tools/api-client.mdx +0 -155
- package/content/tools/cli.mdx +0 -196
- package/content/tools/dashboard-sdk.mdx +0 -35
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Workflows"
|
|
3
|
+
sidebarTitle: "Workflows"
|
|
4
|
+
description: "Mercur's product create, review, and allowlist workflows."
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
This reference lists the Mercur workflows for the Catalog domain. Import them
|
|
8
|
+
from `@mercurjs/core/workflows` and run them against the Medusa container. They
|
|
9
|
+
wrap Medusa's native product flows to add the marketplace layer: the store
|
|
10
|
+
allowlist, the review lifecycle, and the audit trail.
|
|
11
|
+
|
|
12
|
+
## Product workflows
|
|
13
|
+
|
|
14
|
+
| Workflow | Input | Purpose |
|
|
15
|
+
| --- | --- | --- |
|
|
16
|
+
| `createProductsWorkflow` | `{ products[], created_by, additional_data? }` | Create master products, attach attributes/variants, record the submission, allowlist `seller_ids` |
|
|
17
|
+
| `confirmProductsWorkflow` | `{ product_ids[], actor_id?, internal_note? }` | `proposed` → `published` |
|
|
18
|
+
| `rejectProductWorkflow` | `{ product_id, message?, actor_id? }` | `proposed` → `rejected` |
|
|
19
|
+
| `requestProductChangeWorkflow` | `{ product_id, message?, actor_id? }` | Ask the submitter for a revision (stays `proposed`) |
|
|
20
|
+
|
|
21
|
+
## Allowlist & organization workflows
|
|
22
|
+
|
|
23
|
+
| Workflow | Input | Purpose |
|
|
24
|
+
| --- | --- | --- |
|
|
25
|
+
| `linkSellersToProductWorkflow` | `{ id, add?, remove? }` | Add/remove stores on a product's allowlist |
|
|
26
|
+
| `linkSellersToProductCategoryWorkflow` | `{ id, add?, remove? }` | Add/remove stores on a category's allowlist |
|
|
27
|
+
| `assignProductsToCategoryWorkflow` | `{ id, add?, remove? }` | Assign products to a single category |
|
|
28
|
+
|
|
29
|
+
<Note>
|
|
30
|
+
For plain create/update/delete of products, variants, and categories, Mercur
|
|
31
|
+
reuses Medusa's native core-flows (`createProductsWorkflow`,
|
|
32
|
+
`updateProductsWorkflow`, `createProductVariantsWorkflow`, and so on) under the
|
|
33
|
+
hood. The workflows above are the Mercur-specific entry points that add the
|
|
34
|
+
allowlist, review lifecycle, and audit history.
|
|
35
|
+
</Note>
|
|
36
|
+
|
|
37
|
+
To work with records directly instead of through a workflow, see the
|
|
38
|
+
[Service reference](/platform/catalog/reference/service). To run side effects
|
|
39
|
+
when a product changes, see the
|
|
40
|
+
[Event reference](/platform/catalog/reference/events).
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Order commission lines"
|
|
3
|
+
sidebarTitle: "Order commission lines"
|
|
4
|
+
description: "Per-order commission lines, how they're computed, and BigNumber precision."
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
This page covers how commission is recorded on an order and kept in sync as the
|
|
8
|
+
order changes.
|
|
9
|
+
|
|
10
|
+
## Commission line
|
|
11
|
+
|
|
12
|
+
A commission line is the resolved commission for a single order line. It's
|
|
13
|
+
represented by the `CommissionLine` data model (table `commission_line`, id
|
|
14
|
+
prefix `comline`). Each line anchors to either an item (`item_id`) or a shipping
|
|
15
|
+
method (`shipping_method_id`). It records the rate that matched
|
|
16
|
+
(`commission_rate_id`, `code`), the applied `rate`, and the computed `amount`.
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
// A commission line, as written by the refresh workflow
|
|
20
|
+
{
|
|
21
|
+
item_id: "ordli_123",
|
|
22
|
+
shipping_method_id: null,
|
|
23
|
+
commission_rate_id: "comrate_123",
|
|
24
|
+
code: "standard-a1b2c3",
|
|
25
|
+
rate: 10,
|
|
26
|
+
amount: 250, // 10% of a 2500 subtotal
|
|
27
|
+
description: null,
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Lines are generated automatically during checkout. When the cart is split into
|
|
32
|
+
per-seller orders, `refreshOrderCommissionLinesWorkflow` runs against each new
|
|
33
|
+
order. Shipping lines carry a `"Shipping Commission"` description. Item lines
|
|
34
|
+
carry none.
|
|
35
|
+
|
|
36
|
+
## Recomputed on change
|
|
37
|
+
|
|
38
|
+
Commission lines are **derived** data, not a one-time snapshot. The lines are
|
|
39
|
+
recomputed whenever an order's composition changes, such as when an order edit
|
|
40
|
+
is confirmed, a return is received, or a claim or exchange is created. That
|
|
41
|
+
keeps the seller's commission tracking what the customer actually kept.
|
|
42
|
+
|
|
43
|
+
The refresh is **idempotent**: it deletes any existing lines for the affected
|
|
44
|
+
items and shipping methods, then inserts the freshly computed set. Re-running it
|
|
45
|
+
never duplicates lines.
|
|
46
|
+
|
|
47
|
+
<Note>
|
|
48
|
+
Computed lines carry no `id`. The module's `upsertCommissionLines` deletes by
|
|
49
|
+
anchor (`item_id` / `shipping_method_id`) before inserting, which is what
|
|
50
|
+
makes repeated refreshes safe.
|
|
51
|
+
</Note>
|
|
52
|
+
|
|
53
|
+
## BigNumber precision
|
|
54
|
+
|
|
55
|
+
All commission arithmetic uses Medusa's `MathBN` (BigNumber). It's arbitrary
|
|
56
|
+
precision, so percentages and per-currency amounts never accumulate
|
|
57
|
+
floating-point error. A percentage amount is `subtotal × value ÷ 100`. A fixed
|
|
58
|
+
amount is the per-currency value (or the fallback `value`). Each is computed in
|
|
59
|
+
BigNumber before being stored.
|
|
60
|
+
|
|
61
|
+
<Tip>
|
|
62
|
+
Commission lines feed the payout pipeline: when a seller's payout is
|
|
63
|
+
calculated, the order's commission lines are read straight from the commission
|
|
64
|
+
module and deducted from the amount transferred to the seller.
|
|
65
|
+
</Tip>
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Rule matching"
|
|
3
|
+
sidebarTitle: "Rule matching"
|
|
4
|
+
description: "The five dimensions, most-specific-wins resolution, tie-breaks, and shipping."
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
This page covers how Mercur decides which commission rate applies to a given
|
|
8
|
+
order line.
|
|
9
|
+
|
|
10
|
+
## Commission rule
|
|
11
|
+
|
|
12
|
+
A commission rule scopes a rate to part of the catalog. It's represented by the
|
|
13
|
+
`CommissionRule` data model (table `commission_rule`, id prefix `comrule`). A
|
|
14
|
+
rule is a `reference` / `reference_id` pair that belongs to one rate. The
|
|
15
|
+
`reference` names the dimension, and the `reference_id` names the specific
|
|
16
|
+
record.
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
await batchCommissionRulesWorkflow(container).run({
|
|
20
|
+
input: {
|
|
21
|
+
commission_rate_id: "comrate_123",
|
|
22
|
+
create: [
|
|
23
|
+
{ reference: "seller", reference_id: "sel_123" },
|
|
24
|
+
{ reference: "product_category", reference_id: "pcat_shoes" },
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
})
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
A rate with **no** rules is a catch-all that matches every line. A rate with
|
|
31
|
+
rules only matches lines that satisfy them.
|
|
32
|
+
|
|
33
|
+
## The five dimensions
|
|
34
|
+
|
|
35
|
+
A rule's `reference` is one of five dimensions, each resolved against the order
|
|
36
|
+
line's product:
|
|
37
|
+
|
|
38
|
+
| `reference` | Matches when |
|
|
39
|
+
| --- | --- |
|
|
40
|
+
| `product` | The line's product id equals `reference_id` |
|
|
41
|
+
| `product_type` | The product's type id equals `reference_id` |
|
|
42
|
+
| `product_collection` | The product's collection id equals `reference_id` |
|
|
43
|
+
| `product_category` | One of the product's categories equals `reference_id` |
|
|
44
|
+
| `seller` | The seller behind the line's offer equals `reference_id` |
|
|
45
|
+
|
|
46
|
+
<Note>
|
|
47
|
+
Products are the shared master catalog. The `seller` dimension resolves
|
|
48
|
+
through the **offer** on the order line (`item.offer.seller_id`), not through
|
|
49
|
+
product ownership.
|
|
50
|
+
</Note>
|
|
51
|
+
|
|
52
|
+
## Most-specific-wins
|
|
53
|
+
|
|
54
|
+
When several rates match a line, resolution is **AND across dimensions, OR
|
|
55
|
+
within a dimension**. Rules are grouped by `reference`. A rate matches only when
|
|
56
|
+
**every** group it defines has at least one matching rule. Among the matching
|
|
57
|
+
rates, the one scoped on the **most distinct dimensions** wins.
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
Rate A: seller = sel_123 (specificity 1)
|
|
61
|
+
Rate B: seller = sel_123 AND category = pcat_shoes (specificity 2) ← wins
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
<Tip>
|
|
65
|
+
Specificity is the count of **distinct dimensions** a rate scopes on, not the
|
|
66
|
+
number of rules. Two `product_category` rules on one rate still count as a
|
|
67
|
+
single dimension (they OR together).
|
|
68
|
+
</Tip>
|
|
69
|
+
|
|
70
|
+
## Tie-break
|
|
71
|
+
|
|
72
|
+
When two matching rates have equal specificity, the **oldest** rate wins. Rates
|
|
73
|
+
are evaluated `created_at` ascending, so the earliest-created rate is the
|
|
74
|
+
deterministic winner.
|
|
75
|
+
|
|
76
|
+
## Shipping commission
|
|
77
|
+
|
|
78
|
+
Item commission is resolved per line as above. Shipping is different: a
|
|
79
|
+
shipping method is commissioned **only** by the global rate, and only when its
|
|
80
|
+
`include_shipping` flag is on. No scoped rate can commission shipping.
|
|
81
|
+
|
|
82
|
+
<Note>
|
|
83
|
+
`include_tax` is a separate, per-rate toggle. When on, the line's `tax_total`
|
|
84
|
+
is added to the base amount before the rate is applied. This holds for both
|
|
85
|
+
item and shipping commission.
|
|
86
|
+
</Note>
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Rules & rates"
|
|
3
|
+
sidebarTitle: "Rules & rates"
|
|
4
|
+
description: "The commission rate, its fixed and percentage forms, and per-currency amounts."
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
This page covers how a commission rate is modeled and the two ways it can
|
|
8
|
+
express the marketplace's cut.
|
|
9
|
+
|
|
10
|
+
## Commission rate
|
|
11
|
+
|
|
12
|
+
A commission rate is the number the marketplace takes from a sale. It's
|
|
13
|
+
represented by the `CommissionRate` data model (table `commission_rate`, id
|
|
14
|
+
prefix `comrate`). A rate has a `name`, a unique `code`, a `type`, and a
|
|
15
|
+
`value`, plus the `include_tax` and `include_shipping` toggles.
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
const { result } = await createCommissionRatesWorkflow(container).run({
|
|
19
|
+
input: [
|
|
20
|
+
{
|
|
21
|
+
name: "Standard",
|
|
22
|
+
type: CommissionRateType.PERCENTAGE,
|
|
23
|
+
value: 10,
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
})
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
A rate is either **percentage** or **fixed**, set by `type`
|
|
30
|
+
(`CommissionRateType`):
|
|
31
|
+
|
|
32
|
+
| Type | How `value` is read |
|
|
33
|
+
| --- | --- |
|
|
34
|
+
| `percentage` | A percent of the line's base amount (e.g. `10` → 10%) |
|
|
35
|
+
| `fixed` | A flat amount deducted per line |
|
|
36
|
+
|
|
37
|
+
<Note>
|
|
38
|
+
A rate's `code` is unique. When you create a rate without one, the module
|
|
39
|
+
auto-generates a URL-safe code from the `name` (e.g. `"Standard"` →
|
|
40
|
+
`standard-a1b2c3`).
|
|
41
|
+
</Note>
|
|
42
|
+
|
|
43
|
+
## Per-currency amounts
|
|
44
|
+
|
|
45
|
+
A fixed rate can carry a different amount for each currency. This is
|
|
46
|
+
represented by the `CommissionRateValue` data model (table
|
|
47
|
+
`commission_rate_value`, id prefix `comval`). Each value pairs a `currency_code`
|
|
48
|
+
with an `amount`, and the calculation picks the value matching the order's
|
|
49
|
+
currency.
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
await createCommissionRatesWorkflow(container).run({
|
|
53
|
+
input: [
|
|
54
|
+
{
|
|
55
|
+
name: "Flat fee",
|
|
56
|
+
type: CommissionRateType.FIXED,
|
|
57
|
+
value: 5, // fallback when no per-currency value matches
|
|
58
|
+
values: [
|
|
59
|
+
{ currency_code: "usd", amount: 5 },
|
|
60
|
+
{ currency_code: "eur", amount: 4 },
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
})
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
<Tip>
|
|
68
|
+
When no `values` entry matches the order's currency, a fixed rate falls back
|
|
69
|
+
to its scalar `value`. Percentage rates ignore `values` entirely. A percent
|
|
70
|
+
is currency-independent.
|
|
71
|
+
</Tip>
|
|
72
|
+
|
|
73
|
+
## The global commission
|
|
74
|
+
|
|
75
|
+
Every marketplace has exactly one **Global Commission**. This is the rate with
|
|
76
|
+
`is_default` set to `true`. Mercur seeds it at boot (a `0%` percentage rate
|
|
77
|
+
named `Default`) so a rate always exists, and it applies whenever no
|
|
78
|
+
more-specific rate matches a line.
|
|
79
|
+
|
|
80
|
+
<Note>
|
|
81
|
+
The global rate is also the **only** rate that can commission shipping. See
|
|
82
|
+
[Rule matching](/platform/commission/concepts/rule-matching) for how
|
|
83
|
+
specificity and shipping are resolved.
|
|
84
|
+
</Note>
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Batch-update commission rules"
|
|
3
|
+
sidebarTitle: "Batch-update rules"
|
|
4
|
+
description: "Create, update, and delete a rate's rules in a single call."
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
In this guide, you'll learn how to manage the rules that scope a commission rate
|
|
8
|
+
from your own server code, adding, changing, and removing them in one atomic
|
|
9
|
+
operation.
|
|
10
|
+
|
|
11
|
+
## Run the workflow
|
|
12
|
+
|
|
13
|
+
`batchCommissionRulesWorkflow` applies creates, updates, and deletes to a single
|
|
14
|
+
rate's rules in parallel. Pass the target `commission_rate_id` and any of the
|
|
15
|
+
`create`, `update`, and `delete` arrays.
|
|
16
|
+
|
|
17
|
+
```ts title="src/api/custom/rules/route.ts"
|
|
18
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
19
|
+
import { batchCommissionRulesWorkflow } from "@mercurjs/core/workflows"
|
|
20
|
+
|
|
21
|
+
export async function POST(req: MedusaRequest, res: MedusaResponse) {
|
|
22
|
+
const { result } = await batchCommissionRulesWorkflow(req.scope).run({
|
|
23
|
+
input: {
|
|
24
|
+
commission_rate_id: "comrate_123",
|
|
25
|
+
create: [
|
|
26
|
+
{ reference: "seller", reference_id: "sel_123" },
|
|
27
|
+
{ reference: "product_category", reference_id: "pcat_shoes" },
|
|
28
|
+
],
|
|
29
|
+
update: [{ id: "comrule_456", reference_id: "pcat_boots" }],
|
|
30
|
+
delete: ["comrule_789"],
|
|
31
|
+
},
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
res.json(result)
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The result groups the affected rules as `{ created, updated, deleted }`.
|
|
39
|
+
|
|
40
|
+
<Note>
|
|
41
|
+
Every rule's `reference` must be one of the five dimensions: `product`,
|
|
42
|
+
`product_type`, `product_collection`, `product_category`, or `seller`. The
|
|
43
|
+
`reference_id` is the id of the specific record in that dimension.
|
|
44
|
+
</Note>
|
|
45
|
+
|
|
46
|
+
## How scoping changes matching
|
|
47
|
+
|
|
48
|
+
Adding rules **narrows** a rate. Rules on the same dimension OR together. Rules
|
|
49
|
+
across dimensions AND together. The two `create` rules above make the rate match
|
|
50
|
+
only lines that are both from seller `sel_123` **and** in category `pcat_shoes`,
|
|
51
|
+
raising the rate's specificity to `2`.
|
|
52
|
+
|
|
53
|
+
<Tip>
|
|
54
|
+
Increasing a rate's specificity makes it win over less-specific rates on the
|
|
55
|
+
lines it matches. See
|
|
56
|
+
[Rule matching](/platform/commission/concepts/rule-matching) for how
|
|
57
|
+
most-specific-wins and tie-breaks resolve.
|
|
58
|
+
</Tip>
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Create a commission rate"
|
|
3
|
+
sidebarTitle: "Create a rate"
|
|
4
|
+
description: "Create a commission rate programmatically with createCommissionRatesWorkflow."
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
In this guide, you'll learn how to create a commission rate from your own server
|
|
8
|
+
code. This is useful in a seed script, a custom API route, or an onboarding flow.
|
|
9
|
+
|
|
10
|
+
Mercur exposes a `createCommissionRatesWorkflow` that creates one or more
|
|
11
|
+
`CommissionRate` records. Run it from any place that has access to the Medusa
|
|
12
|
+
container.
|
|
13
|
+
|
|
14
|
+
## Run the workflow
|
|
15
|
+
|
|
16
|
+
```ts title="src/api/custom/route.ts"
|
|
17
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
18
|
+
import { createCommissionRatesWorkflow } from "@mercurjs/core/workflows"
|
|
19
|
+
import { CommissionRateType } from "@mercurjs/types"
|
|
20
|
+
|
|
21
|
+
export async function POST(req: MedusaRequest, res: MedusaResponse) {
|
|
22
|
+
const { result } = await createCommissionRatesWorkflow(req.scope).run({
|
|
23
|
+
input: [
|
|
24
|
+
{
|
|
25
|
+
name: "Standard",
|
|
26
|
+
type: CommissionRateType.PERCENTAGE,
|
|
27
|
+
value: 10,
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
res.status(201).json({ commission_rate: result[0] })
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
<Note>
|
|
37
|
+
The workflow takes an **array** of rates and returns the created records. When
|
|
38
|
+
you omit `code`, the module generates a unique one from `name`.
|
|
39
|
+
</Note>
|
|
40
|
+
|
|
41
|
+
## Create a fixed, per-currency rate
|
|
42
|
+
|
|
43
|
+
For a flat fee, use `CommissionRateType.FIXED` and pass per-currency `values`.
|
|
44
|
+
The scalar `value` is the fallback when no currency matches.
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
await createCommissionRatesWorkflow(req.scope).run({
|
|
48
|
+
input: [
|
|
49
|
+
{
|
|
50
|
+
name: "Flat fee",
|
|
51
|
+
type: CommissionRateType.FIXED,
|
|
52
|
+
value: 5,
|
|
53
|
+
values: [
|
|
54
|
+
{ currency_code: "usd", amount: 5 },
|
|
55
|
+
{ currency_code: "eur", amount: 4 },
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
})
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Scope the rate
|
|
63
|
+
|
|
64
|
+
A rate created without rules is a catch-all. To scope it to part of the catalog,
|
|
65
|
+
attach rules with
|
|
66
|
+
[`batchCommissionRulesWorkflow`](/platform/commission/guides/batch-update-rules).
|
|
67
|
+
|
|
68
|
+
<Tip>
|
|
69
|
+
Only the global rate (`is_default`) may commission shipping. To let the global
|
|
70
|
+
rate take a cut of shipping, update it with `include_shipping: true` via
|
|
71
|
+
`updateCommissionRatesWorkflow`.
|
|
72
|
+
</Tip>
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Refresh order commission lines"
|
|
3
|
+
sidebarTitle: "Refresh order lines"
|
|
4
|
+
description: "Recompute an order's commission lines after it changes."
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
In this guide, you'll learn how to recompute the commission lines for an order
|
|
8
|
+
from your own server code. Mercur already refreshes lines automatically at
|
|
9
|
+
checkout and on order changes. Reach for this workflow when you change an order
|
|
10
|
+
outside those paths, or when backfilling.
|
|
11
|
+
|
|
12
|
+
## Run the workflow
|
|
13
|
+
|
|
14
|
+
`refreshOrderCommissionLinesWorkflow` reads each order, resolves the matching
|
|
15
|
+
rate for every item and shipping method, and writes the resulting
|
|
16
|
+
`CommissionLine` records.
|
|
17
|
+
|
|
18
|
+
```ts title="src/api/custom/refresh/route.ts"
|
|
19
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
20
|
+
import { refreshOrderCommissionLinesWorkflow } from "@mercurjs/core/workflows"
|
|
21
|
+
|
|
22
|
+
export async function POST(req: MedusaRequest, res: MedusaResponse) {
|
|
23
|
+
const { result } = await refreshOrderCommissionLinesWorkflow(req.scope).run({
|
|
24
|
+
input: { order_ids: [req.params.id] },
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
res.json({ commission_lines: result })
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
<Note>
|
|
32
|
+
The workflow takes an array of `order_ids`, so you can refresh many orders in
|
|
33
|
+
one run. This is useful for backfilling after you change your commission
|
|
34
|
+
configuration.
|
|
35
|
+
</Note>
|
|
36
|
+
|
|
37
|
+
## Idempotency
|
|
38
|
+
|
|
39
|
+
The refresh is a **delete-then-insert** for each affected item and shipping
|
|
40
|
+
method, so re-running it never duplicates lines. You can call it as often as you
|
|
41
|
+
need without cleaning up first.
|
|
42
|
+
|
|
43
|
+
## When it runs automatically
|
|
44
|
+
|
|
45
|
+
You rarely need to call this by hand. Mercur runs it for you:
|
|
46
|
+
|
|
47
|
+
- **At checkout:** as each per-seller order is created from the split cart.
|
|
48
|
+
- **On order changes:** a subscriber re-runs it when an order edit is
|
|
49
|
+
confirmed, or a return, claim, or exchange is created.
|
|
50
|
+
|
|
51
|
+
<Tip>
|
|
52
|
+
To hook your own logic into these moments, subscribe to the same order events
|
|
53
|
+
rather than re-running this workflow. See the
|
|
54
|
+
[Events reference](/platform/commission/reference/events).
|
|
55
|
+
</Tip>
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Commission"
|
|
3
|
+
sidebarTitle: "Overview"
|
|
4
|
+
description: "Configure how the marketplace takes its cut of every seller order."
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Use Mercur to keep financial control over what share of each sale the
|
|
8
|
+
marketplace keeps and each seller earns.
|
|
9
|
+
|
|
10
|
+
Financial control over the marketplace runs through commission. You set
|
|
11
|
+
policy-based **rates** (fixed or percentage) and scope them to parts of your
|
|
12
|
+
catalog with **rules**. Mercur resolves the right rate for every order line by
|
|
13
|
+
most-specific-wins and writes an auditable **commission line**. That line is the
|
|
14
|
+
exact amount deducted before the seller is paid out, computed in arbitrary
|
|
15
|
+
precision so the numbers reconcile.
|
|
16
|
+
|
|
17
|
+
<Note>
|
|
18
|
+
**Commission = the `CommissionRate` + `CommissionRule` entities.** A rate is
|
|
19
|
+
the number, either a percentage or a fixed amount. Rules scope that rate to a
|
|
20
|
+
slice of the catalog. Every marketplace has one **Global Commission**. This is
|
|
21
|
+
the `is_default` rate that applies when nothing more specific matches.
|
|
22
|
+
</Note>
|
|
23
|
+
|
|
24
|
+
## Key features
|
|
25
|
+
|
|
26
|
+
- **Fixed or percentage:** a percentage of the line, or a flat per-currency amount.
|
|
27
|
+
- **Per-currency amounts:** fixed rates carry an amount per currency, falling back to a default `value`.
|
|
28
|
+
- **Five scoping dimensions:** match on `product`, `product_type`, `product_collection`, `product_category`, and `seller`.
|
|
29
|
+
- **Most-specific-wins:** the rate scoped on the most dimensions wins, and ties break to the oldest rate.
|
|
30
|
+
- **Shipping commission:** only the global rate may commission shipping (`include_shipping`).
|
|
31
|
+
- **Automatic order lines:** a commission line is generated per item and recomputed when an order changes.
|
|
32
|
+
- **BigNumber arithmetic:** all commission math uses arbitrary precision for financial accuracy.
|
|
33
|
+
|
|
34
|
+
## Get started
|
|
35
|
+
|
|
36
|
+
Learn how the domain fits together.
|
|
37
|
+
|
|
38
|
+
<CardGroup cols={2}>
|
|
39
|
+
<Card title="Rules & rates" icon="percent" href="/platform/commission/concepts/rules-and-rates">
|
|
40
|
+
Fixed vs. percentage rates, per-currency amounts, and the global rate.
|
|
41
|
+
</Card>
|
|
42
|
+
<Card title="Rule matching" icon="sliders" href="/platform/commission/concepts/rule-matching">
|
|
43
|
+
The five dimensions, most-specific-wins, tie-breaks, and shipping.
|
|
44
|
+
</Card>
|
|
45
|
+
<Card title="Order commission lines" icon="receipt" href="/platform/commission/concepts/order-commission-lines">
|
|
46
|
+
How per-order lines are computed and kept in sync.
|
|
47
|
+
</Card>
|
|
48
|
+
</CardGroup>
|
|
49
|
+
|
|
50
|
+
## Examples
|
|
51
|
+
|
|
52
|
+
Build against the Commission domain in your own code.
|
|
53
|
+
|
|
54
|
+
<CardGroup cols={2}>
|
|
55
|
+
<Card title="Create a rate" icon="plus" href="/platform/commission/guides/create-a-rate">
|
|
56
|
+
Run `createCommissionRatesWorkflow` from a route or seed script.
|
|
57
|
+
</Card>
|
|
58
|
+
<Card title="Batch-update rules" icon="list-check" href="/platform/commission/guides/batch-update-rules">
|
|
59
|
+
Create, update, and delete a rate's rules in one call.
|
|
60
|
+
</Card>
|
|
61
|
+
<Card title="Refresh order lines" icon="arrows-rotate" href="/platform/commission/guides/refresh-order-commission-lines">
|
|
62
|
+
Recompute commission for an order after it changes.
|
|
63
|
+
</Card>
|
|
64
|
+
</CardGroup>
|
|
65
|
+
|
|
66
|
+
## Resources
|
|
67
|
+
|
|
68
|
+
Data models, workflows, service methods, and events for the Commission domain.
|
|
69
|
+
|
|
70
|
+
<CardGroup cols={2}>
|
|
71
|
+
<Card title="Data models" icon="table" href="/platform/commission/reference/data-models">
|
|
72
|
+
`CommissionRate`, `CommissionRule`, and related entities.
|
|
73
|
+
</Card>
|
|
74
|
+
<Card title="Links" icon="link" href="/platform/commission/reference/links">
|
|
75
|
+
How Commission connects to catalog, sellers, and orders.
|
|
76
|
+
</Card>
|
|
77
|
+
<Card title="Workflows" icon="diagram-project" href="/platform/commission/reference/workflows">
|
|
78
|
+
Rate, rule, and order-line workflows.
|
|
79
|
+
</Card>
|
|
80
|
+
<Card title="Service" icon="gear" href="/platform/commission/reference/service">
|
|
81
|
+
Module service methods for working with records directly.
|
|
82
|
+
</Card>
|
|
83
|
+
<Card title="Events" icon="bell" href="/platform/commission/reference/events">
|
|
84
|
+
How commission stays in sync with order changes.
|
|
85
|
+
</Card>
|
|
86
|
+
</CardGroup>
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Data models"
|
|
3
|
+
sidebarTitle: "Data models"
|
|
4
|
+
description: "The data models owned by the Commission domain."
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
The Commission domain is owned by the **Commission module**. This reference
|
|
8
|
+
lists its data models and their fields. For the full module overview, see the
|
|
9
|
+
[Commission overview](/platform/commission/overview).
|
|
10
|
+
|
|
11
|
+
## CommissionRate
|
|
12
|
+
|
|
13
|
+
Table `commission_rate`, id prefix `comrate`. The rate the marketplace takes
|
|
14
|
+
from a sale.
|
|
15
|
+
|
|
16
|
+
| Field | Type | Notes |
|
|
17
|
+
| --- | --- | --- |
|
|
18
|
+
| `id` | text | Primary key |
|
|
19
|
+
| `name` | text | Searchable |
|
|
20
|
+
| `code` | text | Unique, searchable; auto-generated from `name` when omitted |
|
|
21
|
+
| `type` | enum | `CommissionRateType`, `fixed` or `percentage` |
|
|
22
|
+
| `value` | bigNumber | Percent (for `percentage`) or fallback amount (for `fixed`) |
|
|
23
|
+
| `currency_code` | text | Nullable; when set, the rate applies only to that currency |
|
|
24
|
+
| `include_tax` | boolean | Default `false`; add `tax_total` to the base amount |
|
|
25
|
+
| `include_shipping` | boolean | Default `false`; only meaningful on the global rate |
|
|
26
|
+
| `is_enabled` | boolean | Default `true`; only enabled rates are evaluated |
|
|
27
|
+
| `is_default` | boolean | Default `false`; the single Global Commission |
|
|
28
|
+
|
|
29
|
+
Relations: `rules` (one-to-many `CommissionRule`), `values` (one-to-many
|
|
30
|
+
`CommissionRateValue`).
|
|
31
|
+
|
|
32
|
+
## CommissionRule
|
|
33
|
+
|
|
34
|
+
Table `commission_rule`, id prefix `comrule`. Scopes a rate to a slice of the
|
|
35
|
+
catalog.
|
|
36
|
+
|
|
37
|
+
| Field | Type | Notes |
|
|
38
|
+
| --- | --- | --- |
|
|
39
|
+
| `id` | text | Primary key |
|
|
40
|
+
| `reference` | text | The dimension: `product`, `product_type`, `product_collection`, `product_category`, or `seller` |
|
|
41
|
+
| `reference_id` | text | The id of the record in that dimension |
|
|
42
|
+
| `commission_rate` | relation | The rate this rule belongs to (`belongsTo`) |
|
|
43
|
+
|
|
44
|
+
## CommissionRateValue
|
|
45
|
+
|
|
46
|
+
Table `commission_rate_value`, id prefix `comval`. A per-currency amount for a
|
|
47
|
+
fixed rate.
|
|
48
|
+
|
|
49
|
+
| Field | Type | Notes |
|
|
50
|
+
| --- | --- | --- |
|
|
51
|
+
| `id` | text | Primary key |
|
|
52
|
+
| `currency_code` | text | The currency this amount applies to |
|
|
53
|
+
| `amount` | bigNumber | The flat commission for that currency |
|
|
54
|
+
| `commission_rate` | relation | The rate this value belongs to (`belongsTo`) |
|
|
55
|
+
|
|
56
|
+
## CommissionLine
|
|
57
|
+
|
|
58
|
+
Table `commission_line`, id prefix `comline`. The resolved commission for one
|
|
59
|
+
order line.
|
|
60
|
+
|
|
61
|
+
| Field | Type | Notes |
|
|
62
|
+
| --- | --- | --- |
|
|
63
|
+
| `id` | text | Primary key |
|
|
64
|
+
| `item_id` | text | Nullable; the order line item this line commissions |
|
|
65
|
+
| `shipping_method_id` | text | Nullable; the shipping method this line commissions |
|
|
66
|
+
| `commission_rate_id` | text | Nullable; the rate that matched |
|
|
67
|
+
| `code` | text | The matched rate's code |
|
|
68
|
+
| `rate` | float | The applied rate |
|
|
69
|
+
| `amount` | bigNumber | The computed commission amount |
|
|
70
|
+
| `description` | text | Nullable; `"Shipping Commission"` on shipping lines |
|
|
71
|
+
|
|
72
|
+
<Note>
|
|
73
|
+
A commission line anchors to **either** `item_id` **or** `shipping_method_id`.
|
|
74
|
+
It references those records by id, not through a module link.
|
|
75
|
+
</Note>
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Event reference"
|
|
3
|
+
sidebarTitle: "Events"
|
|
4
|
+
description: "How the Commission domain stays in sync with order changes."
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
The Commission domain does **not** emit its own domain events. Commission lines
|
|
8
|
+
are derived data, so instead of broadcasting changes, the module **subscribes**
|
|
9
|
+
to order lifecycle events and recomputes lines whenever an order's composition
|
|
10
|
+
changes.
|
|
11
|
+
|
|
12
|
+
## Events it reacts to
|
|
13
|
+
|
|
14
|
+
Mercur ships a subscriber (`order-commission-refresh-handler`) that re-runs
|
|
15
|
+
`refreshOrderCommissionLinesWorkflow` for the affected order on each of these
|
|
16
|
+
events:
|
|
17
|
+
|
|
18
|
+
| Event | Emitted when |
|
|
19
|
+
| --- | --- |
|
|
20
|
+
| `OrderEditWorkflowEvents.CONFIRMED` | An order edit is confirmed |
|
|
21
|
+
| `OrderWorkflowEvents.RETURN_RECEIVED` | A return is received |
|
|
22
|
+
| `OrderWorkflowEvents.CLAIM_CREATED` | A claim is created |
|
|
23
|
+
| `OrderWorkflowEvents.EXCHANGE_CREATED` | An exchange is created |
|
|
24
|
+
|
|
25
|
+
Because the refresh is idempotent (delete-then-insert), reacting to several
|
|
26
|
+
events for the same order never duplicates lines.
|
|
27
|
+
|
|
28
|
+
## Run your own side effects
|
|
29
|
+
|
|
30
|
+
To run logic when an order's commission changes, subscribe to the same order
|
|
31
|
+
events the module listens to, then read the refreshed lines from the commission
|
|
32
|
+
module.
|
|
33
|
+
|
|
34
|
+
```ts title="src/subscribers/commission-changed.ts"
|
|
35
|
+
import type { SubscriberArgs, SubscriberConfig } from "@medusajs/framework"
|
|
36
|
+
import { OrderWorkflowEvents } from "@medusajs/framework/utils"
|
|
37
|
+
|
|
38
|
+
export default async function commissionChangedHandler({
|
|
39
|
+
event,
|
|
40
|
+
container,
|
|
41
|
+
}: SubscriberArgs<{ order_id?: string; id?: string }>) {
|
|
42
|
+
const orderId = event.data.order_id ?? event.data.id
|
|
43
|
+
if (!orderId) {
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
// ...read commission lines for the order, notify, sync an external ledger, etc.
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const config: SubscriberConfig = {
|
|
50
|
+
event: OrderWorkflowEvents.RETURN_RECEIVED,
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
<Note>
|
|
55
|
+
Commission is also refreshed at checkout, as each per-seller order is created
|
|
56
|
+
from the split cart. That refresh happens as a **step inside** the checkout
|
|
57
|
+
workflow rather than via a separate event.
|
|
58
|
+
</Note>
|