The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.
TypeScript b2b-marketplacecomposable-commerceecommerceenterpriseheadless-commercemarketplacemedusamedusajsmulti-vendortypescript
docs: split the Magento 2 integration into quickstart, architecture, configuration and reference pages (#1706)
Viktor Holik8f553e560ce7
diff --git a/apps/docs/docs.json b/apps/docs/docs.jsonindex ecd5de403..727d8cf07 100644--- a/apps/docs/docs.json+++ b/apps/docs/docs.json@@ -426,7 +426,19 @@"pages": ["resources/integrations/overview","resources/integrations/stripe-connect",- "resources/integrations/magento2"+ {+ "group": "Magento 2",+ "pages": [+ "resources/integrations/magento2/overview",+ "resources/integrations/magento2/quickstart",+ "resources/integrations/magento2/architecture",+ "resources/integrations/magento2/configuration",+ "resources/integrations/magento2/catalog-and-offers",+ "resources/integrations/magento2/storefront",+ "resources/integrations/magento2/orders-and-payments",+ "resources/integrations/magento2/reference"+ ]+ }]},{@@ -853,6 +865,10 @@]},"redirects": [+ {+ "source": "/resources/integrations/magento2",+ "destination": "/resources/integrations/magento2/overview"+ },{"source": "/welcome","destination": "/learn/introduction"diff --git a/apps/docs/figures/magento2-architecture.mjs b/apps/docs/figures/magento2-architecture.mjsnew file mode 100644index 000000000..cb8edea64--- /dev/null+++ b/apps/docs/figures/magento2-architecture.mjs@@ -0,0 +1,103 @@+const MAGENTO_MODULES = [+ "Mercur_Core",+ "Mercur_Process",+ "Mercur_Connector",+ "Mercur_OfferIndexer",+ "Mercur_Catalog",+ "Mercur_Settlement",+ "Mercur_Frontend",+ "Mercur_GraphQl",+ { tag: "Mercur_Inventory", dashed: true },+]++const CHANNELS = [+ {+ title: "Admin API",+ marker: "mid",+ auth: "secret API key",+ lines: ["GET /admin/offers", "GET /admin/sellers", "…/payments/capture"],+ },+ {+ title: "Store API",+ marker: "mid",+ auth: "publishable key",+ lines: ["POST /store/carts", "/store/shipping-options", "…/carts/:id/complete"],+ },+ {+ title: "Webhooks",+ marker: "violet",+ auth: "HMAC-SHA256",+ lines: ["POST /mercur/webhook", "offer.updated", "shipment.created"],+ },+]++const PLUGIN = ["magento_webhook", "pp_external_external", "/admin/magento/*", "Settings → Magento"]+const CORE = ["seller", "offer", "order-group", "commission", "payout"]++const X = 40+const W = 960+const GAP = 24++export default {+ name: "magento2-architecture",+ width: 1040,+ height: 964,+ alt: "Magento 2, running the nine Mercur modules, sits above Mercur, running @mercurjs/magento2-connector-plugin beside the marketplace modules. Between them are three channels: the Admin API with a secret key and the Store API with a publishable key, which Magento calls, and signed webhooks to POST /mercur/webhook, which Mercur sends.",+ draw(f) {+ const magento = f.panel({ x: X, y: 48, w: W, name: "magento" }, (p) => {+ p.header({ h: 68, marker: "hi", title: "Magento 2", note: "mercurjs/magento2-connector" })+ p.label(24, 68 + 30, "storefront · cart · checkout · payment · your catalog", { size: 15, tone: "mid" })+ const bottom = p.tags(24, 68 + 54, W - 48, MAGENTO_MODULES)+ return bottom + 24+ })++ const cw = (W - 2 * GAP) / 3+ const cx = (i) => X + i * (cw + GAP)+ const chanTop = magento.y + magento.h + 56+ const chanH = 246+ CHANNELS.forEach((c, i) => {+ f.wire([[cx(i) + cw / 2, magento.y + magento.h], [cx(i) + cw / 2, chanTop]])+ f.panel({ x: cx(i), y: chanTop, w: cw, h: chanH, name: c.title }, (p) => {+ p.header({ h: 64, marker: c.marker, title: c.title, pad: 20 })+ p.label(20, 64 + 28, c.auth, { size: 14, tone: "lo", caps: true })+ p.line(0, 64 + 52, cw, 64 + 52, { stroke: f.t.rule })+ c.lines.forEach((line, j) => {+ p.label(20, 64 + 82 + j * 34, line, { size: 15, tone: j === 0 ? "hi" : "text" })+ })+ })+ })++ const chanBottom = chanTop + chanH+ const mercurTop = chanBottom + 56+ CHANNELS.forEach((_, i) => f.wire([[cx(i) + cw / 2, chanBottom], [cx(i) + cw / 2, mercurTop]]))++ const mercur = f.panel({ x: X, y: mercurTop, w: W, name: "mercur" }, (p) => {+ p.header({ h: 68, marker: "hi", title: "Mercur API", note: "withMercur()" })+ let y = 68 + 14+ const rows = [+ { label: "Plugin", sub: "@mercurjs/magento2-connector-plugin", tags: PLUGIN },+ { label: "Core", sub: "@mercurjs/core", tags: CORE },+ ]+ rows.forEach((r, i) => {+ p.label(24, y + 21, r.label, { size: 14, tone: "hi", caps: true })+ p.label(24, y + 46, r.sub, { size: 15, tone: "lo" })+ const bottom = Math.max(p.tags(420, y, W - 420 - 24, r.tags), y + 62)+ y = bottom + 14+ if (i < rows.length - 1) p.line(0, y, W, y, { stroke: f.t.rule })+ y += i < rows.length - 1 ? 14 : 0+ })+ return y + 10+ })++ f.tiles({+ seed: 11,+ density: 0.22,+ clear: [+ { x: X, y: magento.y + magento.h, w: W, h: chanTop - magento.y - magento.h },+ { x: X, y: chanTop, w: W, h: chanH },+ { x: X, y: chanBottom, w: W, h: mercurTop - chanBottom },+ { x: X, y: mercur.y, w: W, h: mercur.h },+ ],+ })+ },+}diff --git a/apps/docs/images/figures/magento2-architecture-dark.svg b/apps/docs/images/figures/magento2-architecture-dark.svgnew file mode 100644index 000000000..e7dc5b78f--- /dev/null+++ b/apps/docs/images/figures/magento2-architecture-dark.svg@@ -0,0 +1,5 @@+<svg xmlns="http://www.w3.org/2000/svg" width="1040" height="964" viewBox="0 0 1040 964" font-family="JetBrains Mono, SF Mono, SFMono-Regular, Menlo, Consolas, Liberation Mono, monospace" role="img" aria-label="Magento 2, running the nine Mercur modules, sits above Mercur, running @mercurjs/magento2-connector-plugin beside the marketplace modules. Between them are three channels: the Admin API with a secret key and the Store API with a publishable key, which Magento calls, and signed webhooks to POST /mercur/webhook, which Mercur sends.">+<title>Magento 2, running the nine Mercur modules, sits above Mercur, running @mercurjs/magento2-connector-plugin beside the marketplace modules. Between them are three channels: the Admin API with a secret key and the Store API with a publishable key, which Magento calls, and signed webhooks to POST /mercur/webhook, which Mercur sends.</title>+<defs><filter id="sh" x="-30%" y="-30%" width="160%" height="170%"><feDropShadow dx="0" dy="18" stdDeviation="22" flood-color="#000000" flood-opacity="0.55"/></filter><filter id="gr" x="0" y="0" width="100%" height="100%"><feTurbulence type="fractalNoise" baseFrequency="0.85" numOctaves="2" seed="7" stitchTiles="stitch"/><feColorMatrix type="saturate" values="0"/><feComponentTransfer><feFuncA type="table" tableValues="0 1"/></feComponentTransfer><feComposite in2="SourceGraphic" operator="in"/></filter><pattern id="dt" width="11" height="11" patternUnits="userSpaceOnUse"><rect x="4.5" y="4.5" width="1.6" height="1.6" fill="#2c2737"/></pattern><clipPath id="c1"><rect x="0" y="0" width="960" height="230"/></clipPath><clipPath id="c2"><rect x="0" y="0" width="304" height="246"/></clipPath><clipPath id="c3"><rect x="0" y="0" width="304" height="246"/></clipPath><clipPath id="c4"><rect x="0" y="0" width="304" height="246"/></clipPath><clipPath id="c5"><rect x="0" y="0" width="960" height="280"/></clipPath></defs>+<rect x="440" y="-88" width="88" height="88" fill="url(#dt)"/><rect x="-87.5" y="0.5" width="87" height="87" fill="none" stroke="#1d1926" stroke-width="1"/><rect x="352" y="0" width="88" height="88" fill="url(#dt)"/><rect x="1056.5" y="0.5" width="87" height="87" fill="none" stroke="#1d1926" stroke-width="1"/><rect x="176" y="88" width="88" height="88" fill="url(#dt)"/><rect x="616" y="88" width="88" height="88" fill="#1d1926"/><rect x="616" y="88" width="88" height="88" fill="#a1a1aa" opacity="0.35" filter="url(#gr)"/><rect x="880.5" y="88.5" width="87" height="87" fill="none" stroke="#1d1926" stroke-width="1"/><rect x="264" y="176" width="88" height="88" fill="url(#dt)"/><rect x="352.5" y="176.5" width="87" height="87" fill="none" stroke="#1d1926" stroke-width="1"/><rect x="880" y="176" width="88" height="88" fill="url(#dt)"/><rect x="1056" y="792" width="88" height="88" fill="#1d1926"/><rect x="1056" y="792" width="88" height="88" fill="#a1a1aa" opacity="0.35" filter="url(#gr)"/><rect x="-88" y="880" width="88" height="88" fill="url(#dt)"/><rect x="88.5" y="968.5" width="87" height="87" fill="none" stroke="#1d1926" stroke-width="1"/><rect x="176" y="968" width="88" height="88" fill="url(#dt)"/><rect x="264" y="968" width="88" height="88" fill="url(#dt)"/><rect x="704" y="968" width="88" height="88" fill="url(#dt)"/><rect x="880" y="968" width="88" height="88" fill="#1d1926"/><rect x="880" y="968" width="88" height="88" fill="#a1a1aa" opacity="0.35" filter="url(#gr)"/><rect x="968" y="968" width="88" height="88" fill="#1d1926"/><rect x="968" y="968" width="88" height="88" fill="#a1a1aa" opacity="0.35" filter="url(#gr)"/><rect x="40" y="48" width="960" height="230" fill="#15121d" filter="url(#sh)"/><rect x="40" y="48" width="960" height="230" fill="#15121d"/><g transform="translate(40 48)"><g clip-path="url(#c1)"><rect x="24" y="29" width="10" height="10" fill="#f4f4f5"/><text x="46" y="40.3" font-size="18" fill="#f4f4f5" font-weight="500">Magento 2</text><text x="936" y="39.3" font-size="15" fill="#71717a" text-anchor="end">mercurjs/magento2-connector</text><line x1="0" y1="68" x2="960" y2="68" stroke="#2b2636" stroke-width="1"/><text x="24" y="103.3" font-size="15" fill="#a1a1aa">storefront · cart · checkout · payment · your catalog</text><rect x="24" y="128" width="123" height="30" fill="#1f1b29"/><text x="36" y="148.3" font-size="15" fill="#a1a1aa">Mercur_Core</text><rect x="157" y="128" width="150" height="30" fill="#1f1b29"/><text x="169" y="148.3" font-size="15" fill="#a1a1aa">Mercur_Process</text><rect x="317" y="128" width="168" height="30" fill="#1f1b29"/><text x="329" y="148.3" font-size="15" fill="#a1a1aa">Mercur_Connector</text><rect x="495" y="128" width="195" height="30" fill="#1f1b29"/><text x="507" y="148.3" font-size="15" fill="#a1a1aa">Mercur_OfferIndexer</text><rect x="700" y="128" width="150" height="30" fill="#1f1b29"/><text x="712" y="148.3" font-size="15" fill="#a1a1aa">Mercur_Catalog</text><rect x="24" y="170" width="177" height="30" fill="#1f1b29"/><text x="36" y="190.3" font-size="15" fill="#a1a1aa">Mercur_Settlement</text><rect x="211" y="170" width="159" height="30" fill="#1f1b29"/><text x="223" y="190.3" font-size="15" fill="#a1a1aa">Mercur_Frontend</text><rect x="380" y="170" width="150" height="30" fill="#1f1b29"/><text x="392" y="190.3" font-size="15" fill="#a1a1aa">Mercur_GraphQl</text><rect x="540.5" y="170.5" width="167" height="29" fill="none" stroke="#3d3749" stroke-width="1" stroke-dasharray="3 3"/><text x="552" y="190.3" font-size="15" fill="#a1a1aa">Mercur_Inventory</text></g></g><rect x="40.5" y="48.5" width="959" height="229" fill="none" stroke="#2b2636" stroke-width="1"/><path d="M192 278 L192 334" fill="none" stroke="#3d3749" stroke-width="1"/><rect x="189" y="331" width="6" height="6" fill="#3d3749"/><rect x="40" y="334" width="304" height="246" fill="#15121d" filter="url(#sh)"/><rect x="40" y="334" width="304" height="246" fill="#15121d"/><g transform="translate(40 334)"><g clip-path="url(#c2)"><rect x="20" y="27" width="10" height="10" fill="#a1a1aa"/><text x="42" y="38.3" font-size="18" fill="#f4f4f5" font-weight="500">Admin API</text><line x1="0" y1="64" x2="304" y2="64" stroke="#2b2636" stroke-width="1"/><text x="20" y="96.9" font-size="14" fill="#71717a" letter-spacing="1.2">SECRET API KEY</text><line x1="0" y1="116" x2="304" y2="116" stroke="#221e2b" stroke-width="1"/><text x="20" y="151.3" font-size="15" fill="#f4f4f5">GET /admin/offers</text><text x="20" y="185.3" font-size="15" fill="#d4d4d8">GET /admin/sellers</text><text x="20" y="219.3" font-size="15" fill="#d4d4d8">…/payments/capture</text></g></g><rect x="40.5" y="334.5" width="303" height="245" fill="none" stroke="#2b2636" stroke-width="1"/><path d="M520 278 L520 334" fill="none" stroke="#3d3749" stroke-width="1"/><rect x="517" y="331" width="6" height="6" fill="#3d3749"/><rect x="368" y="334" width="304" height="246" fill="#15121d" filter="url(#sh)"/><rect x="368" y="334" width="304" height="246" fill="#15121d"/><g transform="translate(368 334)"><g clip-path="url(#c3)"><rect x="20" y="27" width="10" height="10" fill="#a1a1aa"/><text x="42" y="38.3" font-size="18" fill="#f4f4f5" font-weight="500">Store API</text><line x1="0" y1="64" x2="304" y2="64" stroke="#2b2636" stroke-width="1"/><text x="20" y="96.9" font-size="14" fill="#71717a" letter-spacing="1.2">PUBLISHABLE KEY</text><line x1="0" y1="116" x2="304" y2="116" stroke="#221e2b" stroke-width="1"/><text x="20" y="151.3" font-size="15" fill="#f4f4f5">POST /store/carts</text><text x="20" y="185.3" font-size="15" fill="#d4d4d8">/store/shipping-options</text><text x="20" y="219.3" font-size="15" fill="#d4d4d8">…/carts/:id/complete</text></g></g><rect x="368.5" y="334.5" width="303" height="245" fill="none" stroke="#2b2636" stroke-width="1"/><path d="M848 278 L848 334" fill="none" stroke="#3d3749" stroke-width="1"/><rect x="845" y="331" width="6" height="6" fill="#3d3749"/><rect x="696" y="334" width="304" height="246" fill="#15121d" filter="url(#sh)"/><rect x="696" y="334" width="304" height="246" fill="#15121d"/><g transform="translate(696 334)"><g clip-path="url(#c4)"><rect x="20" y="27" width="10" height="10" fill="#a78bfa"/><text x="42" y="38.3" font-size="18" fill="#f4f4f5" font-weight="500">Webhooks</text><line x1="0" y1="64" x2="304" y2="64" stroke="#2b2636" stroke-width="1"/><text x="20" y="96.9" font-size="14" fill="#71717a" letter-spacing="1.2">HMAC-SHA256</text><line x1="0" y1="116" x2="304" y2="116" stroke="#221e2b" stroke-width="1"/><text x="20" y="151.3" font-size="15" fill="#f4f4f5">POST /mercur/webhook</text><text x="20" y="185.3" font-size="15" fill="#d4d4d8">offer.updated</text><text x="20" y="219.3" font-size="15" fill="#d4d4d8">shipment.created</text></g></g><rect x="696.5" y="334.5" width="303" height="245" fill="none" stroke="#2b2636" stroke-width="1"/><path d="M192 580 L192 636" fill="none" stroke="#3d3749" stroke-width="1"/><rect x="189" y="633" width="6" height="6" fill="#3d3749"/><path d="M520 580 L520 636" fill="none" stroke="#3d3749" stroke-width="1"/><rect x="517" y="633" width="6" height="6" fill="#3d3749"/><path d="M848 580 L848 636" fill="none" stroke="#3d3749" stroke-width="1"/><rect x="845" y="633" width="6" height="6" fill="#3d3749"/><rect x="40" y="636" width="960" height="280" fill="#15121d" filter="url(#sh)"/><rect x="40" y="636" width="960" height="280" fill="#15121d"/><g transform="translate(40 636)"><g clip-path="url(#c5)"><rect x="24" y="29" width="10" height="10" fill="#f4f4f5"/><text x="46" y="40.3" font-size="18" fill="#f4f4f5" font-weight="500">Mercur API</text><text x="936" y="39.3" font-size="15" fill="#71717a" text-anchor="end">withMercur()</text><line x1="0" y1="68" x2="960" y2="68" stroke="#2b2636" stroke-width="1"/><text x="24" y="107.9" font-size="14" fill="#f4f4f5" letter-spacing="1.2">PLUGIN</text><text x="24" y="133.3" font-size="15" fill="#71717a">@mercurjs/magento2-connector-plugin</text><rect x="420" y="88" width="159" height="30" fill="#1f1b29"/><text x="432" y="108.3" font-size="15" fill="#a1a1aa">magento_webhook</text><rect x="589" y="88" width="204" height="30" fill="#1f1b29"/><text x="601" y="108.3" font-size="15" fill="#a1a1aa">pp_external_external</text><rect x="420" y="130" width="168" height="30" fill="#1f1b29"/><text x="432" y="150.3" font-size="15" fill="#a1a1aa">/admin/magento/*</text><rect x="598" y="130" width="186" height="30" fill="#1f1b29"/><text x="610" y="150.3" font-size="15" fill="#a1a1aa">Settings → Magento</text><line x1="0" y1="180" x2="960" y2="180" stroke="#221e2b" stroke-width="1"/><text x="24" y="219.9" font-size="14" fill="#f4f4f5" letter-spacing="1.2">CORE</text><text x="24" y="245.3" font-size="15" fill="#71717a">@mercurjs/core</text><rect x="420" y="200" width="78" height="30" fill="#1f1b29"/><text x="432" y="220.3" font-size="15" fill="#a1a1aa">seller</text><rect x="508" y="200" width="69" height="30" fill="#1f1b29"/><text x="520" y="220.3" font-size="15" fill="#a1a1aa">offer</text><rect x="587" y="200" width="123" height="30" fill="#1f1b29"/><text x="599" y="220.3" font-size="15" fill="#a1a1aa">order-group</text><rect x="720" y="200" width="114" height="30" fill="#1f1b29"/><text x="732" y="220.3" font-size="15" fill="#a1a1aa">commission</text><rect x="844" y="200" width="78" height="30" fill="#1f1b29"/><text x="856" y="220.3" font-size="15" fill="#a1a1aa">payout</text></g></g><rect x="40.5" y="636.5" width="959" height="279" fill="none" stroke="#2b2636" stroke-width="1"/>+</svg>\ No newline at end of filediff --git a/apps/docs/images/figures/magento2-architecture-light.svg b/apps/docs/images/figures/magento2-architecture-light.svgnew file mode 100644index 000000000..ab0c8089c--- /dev/null+++ b/apps/docs/images/figures/magento2-architecture-light.svg@@ -0,0 +1,5 @@+<svg xmlns="http://www.w3.org/2000/svg" width="1040" height="964" viewBox="0 0 1040 964" font-family="JetBrains Mono, SF Mono, SFMono-Regular, Menlo, Consolas, Liberation Mono, monospace" role="img" aria-label="Magento 2, running the nine Mercur modules, sits above Mercur, running @mercurjs/magento2-connector-plugin beside the marketplace modules. Between them are three channels: the Admin API with a secret key and the Store API with a publishable key, which Magento calls, and signed webhooks to POST /mercur/webhook, which Mercur sends.">+<title>Magento 2, running the nine Mercur modules, sits above Mercur, running @mercurjs/magento2-connector-plugin beside the marketplace modules. Between them are three channels: the Admin API with a secret key and the Store API with a publishable key, which Magento calls, and signed webhooks to POST /mercur/webhook, which Mercur sends.</title>+<defs><filter id="sh" x="-30%" y="-30%" width="160%" height="170%"><feDropShadow dx="0" dy="18" stdDeviation="22" flood-color="#18181b" flood-opacity="0.07"/></filter><filter id="gr" x="0" y="0" width="100%" height="100%"><feTurbulence type="fractalNoise" baseFrequency="0.85" numOctaves="2" seed="7" stitchTiles="stitch"/><feColorMatrix type="saturate" values="0"/><feComponentTransfer><feFuncA type="table" tableValues="0 1"/></feComponentTransfer><feComposite in2="SourceGraphic" operator="in"/></filter><pattern id="dt" width="11" height="11" patternUnits="userSpaceOnUse"><rect x="4.5" y="4.5" width="1.6" height="1.6" fill="#d9d9de"/></pattern><clipPath id="c1"><rect x="0" y="0" width="960" height="230"/></clipPath><clipPath id="c2"><rect x="0" y="0" width="304" height="246"/></clipPath><clipPath id="c3"><rect x="0" y="0" width="304" height="246"/></clipPath><clipPath id="c4"><rect x="0" y="0" width="304" height="246"/></clipPath><clipPath id="c5"><rect x="0" y="0" width="960" height="280"/></clipPath></defs>+<rect x="440" y="-88" width="88" height="88" fill="url(#dt)"/><rect x="-87.5" y="0.5" width="87" height="87" fill="none" stroke="#ececef" stroke-width="1"/><rect x="352" y="0" width="88" height="88" fill="url(#dt)"/><rect x="1056.5" y="0.5" width="87" height="87" fill="none" stroke="#ececef" stroke-width="1"/><rect x="176" y="88" width="88" height="88" fill="url(#dt)"/><rect x="616" y="88" width="88" height="88" fill="#e4e4e7"/><rect x="616" y="88" width="88" height="88" fill="#71717a" opacity="0.22" filter="url(#gr)"/><rect x="880.5" y="88.5" width="87" height="87" fill="none" stroke="#ececef" stroke-width="1"/><rect x="264" y="176" width="88" height="88" fill="url(#dt)"/><rect x="352.5" y="176.5" width="87" height="87" fill="none" stroke="#ececef" stroke-width="1"/><rect x="880" y="176" width="88" height="88" fill="url(#dt)"/><rect x="1056" y="792" width="88" height="88" fill="#e4e4e7"/><rect x="1056" y="792" width="88" height="88" fill="#71717a" opacity="0.22" filter="url(#gr)"/><rect x="-88" y="880" width="88" height="88" fill="url(#dt)"/><rect x="88.5" y="968.5" width="87" height="87" fill="none" stroke="#ececef" stroke-width="1"/><rect x="176" y="968" width="88" height="88" fill="url(#dt)"/><rect x="264" y="968" width="88" height="88" fill="url(#dt)"/><rect x="704" y="968" width="88" height="88" fill="url(#dt)"/><rect x="880" y="968" width="88" height="88" fill="#e4e4e7"/><rect x="880" y="968" width="88" height="88" fill="#71717a" opacity="0.22" filter="url(#gr)"/><rect x="968" y="968" width="88" height="88" fill="#e4e4e7"/><rect x="968" y="968" width="88" height="88" fill="#71717a" opacity="0.22" filter="url(#gr)"/><rect x="40" y="48" width="960" height="230" fill="#ffffff" filter="url(#sh)"/><rect x="40" y="48" width="960" height="230" fill="#ffffff"/><g transform="translate(40 48)"><g clip-path="url(#c1)"><rect x="24" y="29" width="10" height="10" fill="#18181b"/><text x="46" y="40.3" font-size="18" fill="#18181b" font-weight="500">Magento 2</text><text x="936" y="39.3" font-size="15" fill="#a1a1aa" text-anchor="end">mercurjs/magento2-connector</text><line x1="0" y1="68" x2="960" y2="68" stroke="#e4e4e7" stroke-width="1"/><text x="24" y="103.3" font-size="15" fill="#71717a">storefront · cart · checkout · payment · your catalog</text><rect x="24" y="128" width="123" height="30" fill="#f4f4f5"/><text x="36" y="148.3" font-size="15" fill="#71717a">Mercur_Core</text><rect x="157" y="128" width="150" height="30" fill="#f4f4f5"/><text x="169" y="148.3" font-size="15" fill="#71717a">Mercur_Process</text><rect x="317" y="128" width="168" height="30" fill="#f4f4f5"/><text x="329" y="148.3" font-size="15" fill="#71717a">Mercur_Connector</text><rect x="495" y="128" width="195" height="30" fill="#f4f4f5"/><text x="507" y="148.3" font-size="15" fill="#71717a">Mercur_OfferIndexer</text><rect x="700" y="128" width="150" height="30" fill="#f4f4f5"/><text x="712" y="148.3" font-size="15" fill="#71717a">Mercur_Catalog</text><rect x="24" y="170" width="177" height="30" fill="#f4f4f5"/><text x="36" y="190.3" font-size="15" fill="#71717a">Mercur_Settlement</text><rect x="211" y="170" width="159" height="30" fill="#f4f4f5"/><text x="223" y="190.3" font-size="15" fill="#71717a">Mercur_Frontend</text><rect x="380" y="170" width="150" height="30" fill="#f4f4f5"/><text x="392" y="190.3" font-size="15" fill="#71717a">Mercur_GraphQl</text><rect x="540.5" y="170.5" width="167" height="29" fill="none" stroke="#c4c4cc" stroke-width="1" stroke-dasharray="3 3"/><text x="552" y="190.3" font-size="15" fill="#71717a">Mercur_Inventory</text></g></g><rect x="40.5" y="48.5" width="959" height="229" fill="none" stroke="#e4e4e7" stroke-width="1"/><path d="M192 278 L192 334" fill="none" stroke="#c4c4cc" stroke-width="1"/><rect x="189" y="331" width="6" height="6" fill="#c4c4cc"/><rect x="40" y="334" width="304" height="246" fill="#ffffff" filter="url(#sh)"/><rect x="40" y="334" width="304" height="246" fill="#ffffff"/><g transform="translate(40 334)"><g clip-path="url(#c2)"><rect x="20" y="27" width="10" height="10" fill="#71717a"/><text x="42" y="38.3" font-size="18" fill="#18181b" font-weight="500">Admin API</text><line x1="0" y1="64" x2="304" y2="64" stroke="#e4e4e7" stroke-width="1"/><text x="20" y="96.9" font-size="14" fill="#a1a1aa" letter-spacing="1.2">SECRET API KEY</text><line x1="0" y1="116" x2="304" y2="116" stroke="#ededf0" stroke-width="1"/><text x="20" y="151.3" font-size="15" fill="#18181b">GET /admin/offers</text><text x="20" y="185.3" font-size="15" fill="#3f3f46">GET /admin/sellers</text><text x="20" y="219.3" font-size="15" fill="#3f3f46">…/payments/capture</text></g></g><rect x="40.5" y="334.5" width="303" height="245" fill="none" stroke="#e4e4e7" stroke-width="1"/><path d="M520 278 L520 334" fill="none" stroke="#c4c4cc" stroke-width="1"/><rect x="517" y="331" width="6" height="6" fill="#c4c4cc"/><rect x="368" y="334" width="304" height="246" fill="#ffffff" filter="url(#sh)"/><rect x="368" y="334" width="304" height="246" fill="#ffffff"/><g transform="translate(368 334)"><g clip-path="url(#c3)"><rect x="20" y="27" width="10" height="10" fill="#71717a"/><text x="42" y="38.3" font-size="18" fill="#18181b" font-weight="500">Store API</text><line x1="0" y1="64" x2="304" y2="64" stroke="#e4e4e7" stroke-width="1"/><text x="20" y="96.9" font-size="14" fill="#a1a1aa" letter-spacing="1.2">PUBLISHABLE KEY</text><line x1="0" y1="116" x2="304" y2="116" stroke="#ededf0" stroke-width="1"/><text x="20" y="151.3" font-size="15" fill="#18181b">POST /store/carts</text><text x="20" y="185.3" font-size="15" fill="#3f3f46">/store/shipping-options</text><text x="20" y="219.3" font-size="15" fill="#3f3f46">…/carts/:id/complete</text></g></g><rect x="368.5" y="334.5" width="303" height="245" fill="none" stroke="#e4e4e7" stroke-width="1"/><path d="M848 278 L848 334" fill="none" stroke="#c4c4cc" stroke-width="1"/><rect x="845" y="331" width="6" height="6" fill="#c4c4cc"/><rect x="696" y="334" width="304" height="246" fill="#ffffff" filter="url(#sh)"/><rect x="696" y="334" width="304" height="246" fill="#ffffff"/><g transform="translate(696 334)"><g clip-path="url(#c4)"><rect x="20" y="27" width="10" height="10" fill="#7c3aed"/><text x="42" y="38.3" font-size="18" fill="#18181b" font-weight="500">Webhooks</text><line x1="0" y1="64" x2="304" y2="64" stroke="#e4e4e7" stroke-width="1"/><text x="20" y="96.9" font-size="14" fill="#a1a1aa" letter-spacing="1.2">HMAC-SHA256</text><line x1="0" y1="116" x2="304" y2="116" stroke="#ededf0" stroke-width="1"/><text x="20" y="151.3" font-size="15" fill="#18181b">POST /mercur/webhook</text><text x="20" y="185.3" font-size="15" fill="#3f3f46">offer.updated</text><text x="20" y="219.3" font-size="15" fill="#3f3f46">shipment.created</text></g></g><rect x="696.5" y="334.5" width="303" height="245" fill="none" stroke="#e4e4e7" stroke-width="1"/><path d="M192 580 L192 636" fill="none" stroke="#c4c4cc" stroke-width="1"/><rect x="189" y="633" width="6" height="6" fill="#c4c4cc"/><path d="M520 580 L520 636" fill="none" stroke="#c4c4cc" stroke-width="1"/><rect x="517" y="633" width="6" height="6" fill="#c4c4cc"/><path d="M848 580 L848 636" fill="none" stroke="#c4c4cc" stroke-width="1"/><rect x="845" y="633" width="6" height="6" fill="#c4c4cc"/><rect x="40" y="636" width="960" height="280" fill="#ffffff" filter="url(#sh)"/><rect x="40" y="636" width="960" height="280" fill="#ffffff"/><g transform="translate(40 636)"><g clip-path="url(#c5)"><rect x="24" y="29" width="10" height="10" fill="#18181b"/><text x="46" y="40.3" font-size="18" fill="#18181b" font-weight="500">Mercur API</text><text x="936" y="39.3" font-size="15" fill="#a1a1aa" text-anchor="end">withMercur()</text><line x1="0" y1="68" x2="960" y2="68" stroke="#e4e4e7" stroke-width="1"/><text x="24" y="107.9" font-size="14" fill="#18181b" letter-spacing="1.2">PLUGIN</text><text x="24" y="133.3" font-size="15" fill="#a1a1aa">@mercurjs/magento2-connector-plugin</text><rect x="420" y="88" width="159" height="30" fill="#f4f4f5"/><text x="432" y="108.3" font-size="15" fill="#71717a">magento_webhook</text><rect x="589" y="88" width="204" height="30" fill="#f4f4f5"/><text x="601" y="108.3" font-size="15" fill="#71717a">pp_external_external</text><rect x="420" y="130" width="168" height="30" fill="#f4f4f5"/><text x="432" y="150.3" font-size="15" fill="#71717a">/admin/magento/*</text><rect x="598" y="130" width="186" height="30" fill="#f4f4f5"/><text x="610" y="150.3" font-size="15" fill="#71717a">Settings → Magento</text><line x1="0" y1="180" x2="960" y2="180" stroke="#ededf0" stroke-width="1"/><text x="24" y="219.9" font-size="14" fill="#18181b" letter-spacing="1.2">CORE</text><text x="24" y="245.3" font-size="15" fill="#a1a1aa">@mercurjs/core</text><rect x="420" y="200" width="78" height="30" fill="#f4f4f5"/><text x="432" y="220.3" font-size="15" fill="#71717a">seller</text><rect x="508" y="200" width="69" height="30" fill="#f4f4f5"/><text x="520" y="220.3" font-size="15" fill="#71717a">offer</text><rect x="587" y="200" width="123" height="30" fill="#f4f4f5"/><text x="599" y="220.3" font-size="15" fill="#71717a">order-group</text><rect x="720" y="200" width="114" height="30" fill="#f4f4f5"/><text x="732" y="220.3" font-size="15" fill="#71717a">commission</text><rect x="844" y="200" width="78" height="30" fill="#f4f4f5"/><text x="856" y="220.3" font-size="15" fill="#71717a">payout</text></g></g><rect x="40.5" y="636.5" width="959" height="279" fill="none" stroke="#e4e4e7" stroke-width="1"/>+</svg>\ No newline at end of filediff --git a/apps/docs/learn/use-cases/marketplace-inside-store.mdx b/apps/docs/learn/use-cases/marketplace-inside-store.mdxindex fea5939c7..585b3fe5a 100644--- a/apps/docs/learn/use-cases/marketplace-inside-store.mdx+++ b/apps/docs/learn/use-cases/marketplace-inside-store.mdx@@ -6,7 +6,7 @@ description: "Sell third-party seller offers next to your own products in a storYou already sell your own products on a platform such as Magento 2 or Adobe Commerce, and you want third-party sellers on the same product page and in the same checkout, without moving your catalog or your payments. Your store stays the storefront. Mercur becomes the marketplace layer behind it: sellers log into the vendor panel to list offers against your products and ship their orders, and a connector keeps the two systems in step.-<Card title="Magento 2 integration" icon="store" href="/resources/integrations/magento2">+<Card title="Magento 2 integration" icon="store" href="/resources/integrations/magento2/overview">Install the Mercur plugin and the Magento connector, connect the two stores, run the first sync and place a mixed first-party and seller order.</Card>@@ -16,13 +16,13 @@ You already sell your own products on a platform such as Magento 2 or Adobe Comm## Use cases<CardGroup cols={2}>- <Card title="Sell seller offers next to your stock" icon="store" href="/resources/integrations/magento2">+ <Card title="Sell seller offers next to your stock" icon="store" href="/resources/integrations/magento2/overview">Seller offers appear in a buy box on your product page; your own stock stays one of the candidates and sells exactly as before.</Card><Card title="Let sellers compete on your SKUs" icon="tags" href="/platform/offer/overview">Push your catalog to Mercur so sellers can offer on it, and match their offers to your products by SKU or EAN.</Card>- <Card title="Keep checkout and payment where they are" icon="cart-shopping" href="/resources/integrations/magento2#how-a-mixed-order-flows">+ <Card title="Keep checkout and payment where they are" icon="cart-shopping" href="/resources/integrations/magento2/architecture#anatomy-of-a-checkout">The shopper pays once in your store. Seller lines are mirrored into Mercur and captured only after your invoice is paid.</Card><Card title="Split per seller, commission and pay out" icon="money-bill-transfer" href="/platform/order-group/overview">@@ -47,7 +47,7 @@ A store that is live has a storefront, a theme, integrations, a payment provider| Sellers, their offers, their panel | | ✔ || One order per seller, commissions, payouts | | ✔ |-The integration has two halves. A plugin on the Mercur API, [`@mercurjs/magento2-connector-plugin`](/resources/integrations/magento2), adds outbound webhooks, an external payment provider and the admin routes the connector needs. A Composer package of Magento modules, [`mercurjs/magento2-connector`](https://github.com/mercurjs/magento2-connector), does the rest:+The integration has two halves. A plugin on the Mercur API, [`@mercurjs/magento2-connector-plugin`](/resources/integrations/magento2/overview), adds outbound webhooks, an external payment provider and the admin routes the connector needs. A Composer package of Magento modules, [`mercurjs/magento2-connector`](https://github.com/mercurjs/magento2-connector), does the rest:- **Mercur → your store:** sellers, their offers with prices per website and stock, and published seller products imported as configurable products with images. Webhooks trigger a delta sync; cron is the floor.- **Your store → Mercur:** your attribute and category taxonomy, optionally your own products so sellers can offer on them, and every order with seller lines once it reaches a configured status.@@ -56,7 +56,7 @@ The integration has two halves. A plugin on the Mercur API, [`@mercurjs/magento2Sellers use the same vendor panel and the same [Offer](/platform/offer/overview), [Order Group](/platform/order-group/overview), [Commission](/platform/commission/overview) and [Payout](/platform/payout/overview) modules as a standalone marketplace. Magento 2 is the storefront platform supported today; the same split applies to any platform that can mirror offers and call the Store API during checkout.<CardGroup cols={2}>- <Card title="Magento 2 integration" icon="store" href="/resources/integrations/magento2">+ <Card title="Magento 2 integration" icon="store" href="/resources/integrations/magento2/overview">The setup guide: plugin, connector, configuration, first sync.</Card><Card title="Standalone marketplace" icon="arrow-right-arrow-left" href="/learn/use-cases/standalone-marketplace">diff --git a/apps/docs/resources/integrations/magento2.mdx b/apps/docs/resources/integrations/magento2.mdxdeleted file mode 100644index a5d745abc..000000000--- a/apps/docs/resources/integrations/magento2.mdx+++ /dev/null@@ -1,155 +0,0 @@-----title: "Magento 2 marketplace integration"-sidebarTitle: "Magento 2"-description: "Turn your Magento 2 or Adobe Commerce store into a multi-vendor marketplace with Mercur. Install the connector, sync seller offers, and split each order per seller."------The Magento 2 connector lets a store you already run sell marketplace offers next to its own catalog. Magento keeps the storefront, cart, checkout, payment capture and your first-party products. Mercur keeps sellers, their offers, the split of one checkout into one order per seller, commission lines and payouts.--The integration has two halves:--- **`@mercurjs/magento2-connector-plugin`**, a plugin for your Mercur API that adds outbound webhooks, an external payment provider and a few admin routes-- **`mercurjs/magento2-connector`**, a Composer package of Magento modules that mirrors sellers and offers into Magento and talks to Mercur during checkout--<Tip>- This page is the setup guide. The connector's source, module layout and development workflow live in the [magento2-connector repository](https://github.com/mercurjs/magento2-connector).-</Tip>--## Quick start--<Steps>- <Step title="Install the plugin in Mercur">- Add the plugin and register its payment provider in `medusa-config.ts`:-- ```ts- module.exports = withMercur({- plugins: [- { resolve: "@mercurjs/magento2-connector-plugin", options: {} },- ],- modules: [- {- resolve: "@medusajs/medusa/payment",- options: {- providers: [- {- resolve: "@mercurjs/magento2-connector-plugin/providers/payment-external",- id: "external",- },- ],- },- },- ],- })- ```-- Run `medusa db:migrate` afterwards. The provider is registered as `pp_external_external`; it records a payment Magento already captured instead of charging anyone.-- Then enable it for the region your Magento website sells in: open the region in the Mercur admin and add **pp_external_external** to its payment providers. The shadow cart cannot complete without it.- </Step>- <Step title="Install the Magento package">- In your Magento root. The package is installed from its Git repository until it is published to Packagist, so add the repository first:-- ```bash- composer config repositories.mercur vcs https://github.com/mercurjs/magento2-connector- composer require mercurjs/magento2-connector:dev-main- bin/magento module:enable Mercur_Core Mercur_Process Mercur_Connector \- Mercur_OfferIndexer Mercur_Catalog Mercur_Settlement Mercur_Frontend Mercur_GraphQl- # Only on stores that run Multi-Source Inventory:- bin/magento module:enable Mercur_Inventory- bin/magento setup:upgrade- bin/magento setup:di:compile- bin/magento cache:flush- ```- </Step>- <Step title="Get API details">- You need four values from Mercur:-- - **Admin API key**: create a secret API key under **Settings → API keys**. If your deployment runs a roles module, bind it to a role that holds only the `integrations` permission; without one the key has full admin access, so treat it like an admin password- - **Publishable API key**: the publishable key of the sales channel the shadow cart is created in- - **Sales channel ID** and **Region ID**: the channel and the region whose prices the Magento website shows, one region per website- </Step>- <Step title="Connect Magento">- In Magento open **Stores → Configuration → Mercur → Marketplace** and enter the API URL and the four values above. Choose a best offer rule: lowest price, your own stock first, or premium sellers first.- </Step>- <Step title="Register the webhook">- In the Mercur admin open **Settings → Magento → Add endpoint**, enter `https://your_shop_domain/mercur/webhook`, keep every event selected, and copy the signing secret. The connector needs the fulfillment, shipment, delivery, return and refund events to keep orders in step. It is shown once. Paste it into the Magento configuration under **Webhooks → Signing secret**.- </Step>- <Step title="Run the first sync">- Push your taxonomy, then mirror everything:-- ```bash- bin/magento mercur:sync taxonomy- bin/magento mercur:sync full- ```-- Cron keeps the mirror current afterwards: sellers every 15 minutes, offers every 5 minutes, published products hourly, a full resync every night. Each run is a process under **Mercur → Processes** in the Magento admin.- </Step>-</Steps>--## How a mixed order flows--A shopper buys one of your own products and one seller offer in the same checkout and pays once:--1. The product page lists every active seller offer next to your own stock, with its price for that website, any price list strike-through, quantity tiers and an estimated delivery date. Adding an offer marks the cart line as a marketplace line priced by the offer and labels it "Sold by" the seller. The same works through REST and GraphQL with `mercur_offer_id`.-2. The cart and the checkout group the marketplace lines by seller. Magento copies them into a shadow Mercur cart, asks Mercur for each seller's shipping options and lets the shopper pick one per seller; the sum is the "Seller shipping" total. Your own carriers only price your own lines, and a cart of seller lines only gets the "Shipped by the sellers" method.-3. The shopper pays in Magento. The invoice includes seller shipping.-4. After the order is placed, Magento records the capture on the external payment provider and completes the Mercur cart. Mercur answers with an order group, one order per seller, and Magento stores those ids on the order and its lines.-5. Sellers fulfill in the vendor panel. Each shipped fulfillment becomes its own Magento shipment with its tracking numbers, so partial and multi-parcel deliveries show up as they happen. Deliveries, returns and cancellations update the line's marketplace status, shown to the shopper in their account and to you in the admin.-6. Mercur computes commission lines when the cart completes and pays sellers from the recorded capture.--If Mercur is unreachable at step 4, the Magento order still succeeds and the `order_retry` process completes the Mercur side on its next run.--## Refunds--| Starts in | What happens |-| --- | --- |-| Magento | A credit memo on marketplace lines is reported to Mercur per seller order, with seller shipping split by what each seller charged, so commission lines and payout balances follow |-| Mercur, a seller or operator refund | Mercur sends `order.refund_requested`; Magento creates an adjustment credit memo and refunds the shopper online when the invoice was captured online |-| Mercur, a canceled seller order | Magento refunds that seller's lines and shipping |--A `refunds` process every 15 minutes picks up any refund whose webhook did not arrive.--## Essential practices--### One region per website--Offer prices are read for the region configured on each Magento website, including Mercur price lists. A store with a US and an EU website needs two Mercur regions and two website-scoped values of **Mercur region ID**, and each website's base currency must match its region's currency.--### Set delivery estimates--Under **Mercur → Marketplace → Delivery estimates** set the order cut-off time, business days and transit days for each website. A Mercur shipping option can carry its own `transit_days_min` and `transit_days_max` in its data.--### Keep the operator's stock as a candidate--Your own product is always one of the ways to buy a SKU. The best offer rule decides whether it wins over a cheaper seller; `operator_first` keeps your stock on top whenever it is in stock.--### Let webhooks drive, keep cron as the floor--Offer, seller and product events enqueue the matching delta sync within a minute. The cron schedules exist so the mirror heals after a missed delivery; a full nightly resync removes anything a delta could not see.--## Your products or seller offers--| Situation | What happens |-| --- | --- |-| A product only you sell | A normal Magento line: your price, your stock, your carriers |-| A product only sellers sell | Imported from Mercur, as a configurable product when its variant axes are Magento attributes; it is in stock while an offer is available and every line is a marketplace line |-| A product both you and sellers sell | Same SKU, one buy box; the best offer rule picks the default and the shopper can choose another. When you run out, the product stays buyable from sellers |--Each seller has a page at `/seller/{handle}` listing what they sell on your store. In the Magento admin, **Mercur → Sellers** and **Mercur → Offers** show the mirror, orders show each seller order with its status, and the product page lists the offers for that SKU.--## Next steps--<CardGroup cols={2}>- <Card title="Connector repository" icon="github" href="https://github.com/mercurjs/magento2-connector">- Modules, development workflow, and the webhook handler registry.- </Card>- <Card title="Offer module" icon="tag" href="/platform/offer/overview">- How offers carry seller SKU, price, inventory and shipping.- </Card>- <Card title="Order Group module" icon="layer-group" href="/platform/order-group/overview">- How one checkout becomes one order per seller.- </Card>- <Card title="Commission module" icon="percent" href="/platform/commission/overview">- How commission lines are computed at completion.- </Card>-</CardGroup>diff --git a/apps/docs/resources/integrations/magento2/architecture.mdx b/apps/docs/resources/integrations/magento2/architecture.mdxnew file mode 100644index 000000000..f6c7bd036--- /dev/null+++ b/apps/docs/resources/integrations/magento2/architecture.mdx@@ -0,0 +1,111 @@+---+title: "Magento 2 architecture"+sidebarTitle: "Architecture"+description: "What runs in Magento and in Mercur, the three channels between them, how the mirror stays current, and how one checkout becomes one order per seller."+---++The connector keeps two systems in step without making either depend on the other at every request. Magento holds a local mirror of Mercur's sellers and offers and serves the storefront from it. Mercur stays the source of truth for marketplace data and tells Magento when it changes. They only talk in real time during checkout, when Magento needs seller shipping prices and an order per seller.++<img className="block dark:hidden" src="/images/figures/magento2-architecture-light.svg" alt="Magento 2, running the nine Mercur modules, sits above Mercur, running @mercurjs/magento2-connector-plugin beside the marketplace modules. Between them are three channels: the Admin API with a secret key and the Store API with a publishable key, which Magento calls, and signed webhooks to POST /mercur/webhook, which Mercur sends." />+<img className="hidden dark:block" src="/images/figures/magento2-architecture-dark.svg" alt="Magento 2, running the nine Mercur modules, sits above Mercur, running @mercurjs/magento2-connector-plugin beside the marketplace modules. Between them are three channels: the Admin API with a secret key and the Store API with a publishable key, which Magento calls, and signed webhooks to POST /mercur/webhook, which Mercur sends." />++## The two halves++### In Mercur: `@mercurjs/magento2-connector-plugin`++A Medusa plugin you add to your Mercur API. It adds four things:++- **The `magento_webhook` module**: webhook endpoints and a delivery log. Every delivery is signed, retried on failure and kept for inspection.+- **The `pp_external_external` payment provider**: it records a payment that Magento collected. It authorizes, captures, cancels and refunds on paper only, so no money moves through Mercur at checkout.+- **Admin routes under `/admin/magento`**: connection status, webhook endpoints, and the capture, cancel and refund calls Magento makes after checkout.+- **Settings → Magento** in the admin panel: connection status, endpoints and their delivery history.++### In Magento: `mercurjs/magento2-connector`++A Composer package of nine modules. Each one owns one part of the job:++| Module | Responsibility |+| --- | --- |+| `Mercur_Core` | Configuration, the Mercur API client, logging to `var/log/mercur.log` |+| `Mercur_Process` | The background job table, its runner and cron, the `mercur:*` commands and the **Processes** grid |+| `Mercur_Connector` | Seller and offer mirror, offer lines in the cart, the Mercur cart behind checkout, seller shipping, order placement, the webhook endpoint, fulfillment sync |+| `Mercur_OfferIndexer` | The best offer per SKU and website, and listing prices |+| `Mercur_Catalog` | Taxonomy push, product push, seller product import, stock from offers |+| `Mercur_Settlement` | Credit memos reported to Mercur, refunds from Mercur executed in Magento |+| `Mercur_Frontend` | Product page offers, seller panels in cart and checkout, seller pages, marketplace orders in the customer account |+| `Mercur_GraphQl` | Offers, buy box, seller shipping and seller data in GraphQL |+| `Mercur_Inventory` | Optional, for Multi-Source Inventory: keeps seller lines out of salable checks, reservations and source deduction |++## Three channels++Every exchange between the two systems goes through one of three channels:++| Channel | Direction | Authenticated with | Used for |+| --- | --- | --- | --- |+| Admin API | Magento → Mercur | Secret admin API key | Reading sellers, offers, products and seller orders. Pushing taxonomy and products. Confirming captures, cancellations and refunds |+| Store API | Magento → Mercur | Publishable API key | The Mercur cart behind each checkout: lines, address, seller shipping, payment session, completion. Per-website offer prices |+| Webhooks | Mercur → Magento | HMAC-SHA256 signature | Telling Magento that offers, sellers, products or seller orders changed, and asking it to execute refunds |++Magento never exposes an API that Mercur calls besides the webhook endpoint, `POST /mercur/webhook`.++## Keeping the mirror current++The storefront never asks Mercur what a seller sells. It reads the mirror: `mercur_seller`, `mercur_offer`, `mercur_offer_price` per website, and the best-offer index. Three mechanisms keep that mirror current, each a backstop for the one before it.++1. **Webhooks.** When an offer, seller or product changes, Mercur posts the event to Magento. Magento doesn't apply the payload. It queues a delta sync of that kind, which reads everything changed since the last run from the Admin API.+2. **Cron.** Each sync also runs on a schedule: sellers every 15 minutes, offers every 5 minutes, published products hourly. A missed webhook delays a change by one schedule at most.+3. **A nightly full resync.** At 02:00 every mirror is rebuilt from scratch, and anything Mercur deleted that a delta couldn't see is removed.++A delta sync reads every record updated since the last run. Offer and seller deltas include deleted records, so a withdrawn offer or a removed seller disappears from the storefront without waiting for the full resync.++### Processes++All background work runs as a **process**: a row in `mercur_process` with a task code, parameters, status, attempt count and output log. Webhooks, cron and the admin all queue processes the same way, and one runner executes them:++- The `mercur_process_run_pending` cron job runs every minute under a global lock, so two cron workers never run the same process.+- A process queued while an identical one (same task and parameters) is still pending or running is merged into it. A burst of 50 offer webhooks produces one offer sync.+- A task that asks to retry later is rescheduled with exponential backoff, from 60 seconds up to an hour, until it reaches its maximum attempts.+- A process with no output for longer than the timeout (one hour by default) is marked **Timed out**.+- A full resync queues one child process per step, so each step has its own status and log.++Every process is visible under **Mercur → Processes**, where you can run, stop and delete processes and read their output.++## Anatomy of a checkout++A shopper buys one of your products and one seller offer, and pays once.++1. **Add to cart.** The seller's line carries a `mercur_offer_id`. Magento prices it from the offer for the current website and labels it "Sold by" the seller. Your own line is a normal Magento line.+2. **Mirror the cart in Mercur.** When totals are collected, Magento creates a Mercur cart in the website's region and sales channel and copies the seller lines into it. Your own lines never leave Magento.+3. **Quote seller shipping.** Magento sends the address to the Mercur cart and reads the shipping options, grouped by seller. The shopper picks one per seller, or the cheapest is used. Their sum is the **Seller shipping** total, taxed with your shipping tax class.+4. **Place the order.** The shopper pays through your Magento payment method. Nothing is sent to Mercur yet.+5. **Create the seller orders.** Once the order is committed in one of the configured statuses (`pending` or `processing` by default), Magento adds an authorized payment session on `pp_external_external`, with the Magento order number as its reference, and completes the Mercur cart. Mercur splits it into an order group with one order per seller and computes commission lines.+6. **Capture.** When Magento invoices the order and the invoice is paid, it calls the capture route. Mercur captures the external payment and splits it across the seller orders, so payouts only follow money you actually collected.+7. **Fulfill.** Sellers ship from the vendor panel. Each fulfillment Mercur reports becomes a Magento shipment with its tracking numbers.++See [Orders and payments](/resources/integrations/magento2/orders-and-payments) for cancellations, returns and refunds.++## When something fails++The connector is built so that Mercur being slow or down never loses a Magento order.++| What fails | What happens |+| --- | --- |+| Seller shipping can't be quoted at checkout | The shopper sees "Marketplace shipping could not be quoted. Please try again." and can't place the order until it can be |+| Mercur is down when the order is placed | The Magento order succeeds. The `order_retry` process creates it in Mercur on its next run, every 10 minutes by default |+| The capture call fails on invoice | The invoice succeeds, the order gets a comment, and `order_retry` confirms the capture later |+| Magento is down when Mercur sends a webhook | Mercur retries after 1 minute, 5 minutes, 30 minutes, 2 hours and 12 hours, then marks the delivery **Gave up**. You can redeliver it from the admin. Cron syncs cover the gap |+| A webhook handler throws in Magento | Magento answers `500` and forgets the delivery id, so Mercur's retry runs it again |+| Mercur delivers the same webhook twice | Magento recognises the `x-mercur-delivery` id and answers `{"received":true,"duplicate":true}` without running handlers |+| A refund webhook never arrives | The `refunds` process polls recent seller orders every 15 minutes and executes any refund it missed |++The admin order view has **Send to marketplace**, **Capture marketplace payment** and **Resync marketplace status** buttons for anything that needs a push by hand.++## What Magento stores++Besides the mirror tables, the connector adds its own columns to Magento's sales tables, so every order line knows where it came from:++- **Cart and order lines** carry the offer, the seller, the Mercur line item, the seller order and a marketplace status such as `shipped` or `refused`.+- **Orders** carry the Mercur cart and order group, the seller shipping amounts with their tax, and when the order was sent and captured.+- **Shipments** carry the Mercur fulfillment they record. **Credit memos** carry the Mercur refund they executed, or whether they were reported.++The full list is in the [reference](/resources/integrations/magento2/reference#database).diff --git a/apps/docs/resources/integrations/magento2/catalog-and-offers.mdx b/apps/docs/resources/integrations/magento2/catalog-and-offers.mdxnew file mode 100644index 000000000..8e15ab47e--- /dev/null+++ b/apps/docs/resources/integrations/magento2/catalog-and-offers.mdx@@ -0,0 +1,137 @@+---+title: "Catalog and offers"+sidebarTitle: "Catalog and offers"+description: "How sellers and offers reach Magento, how a SKU's buy box is decided, and how products move between the two catalogs in both directions."+---++Magento and Mercur each keep a catalog. Yours lives in Magento. Sellers' products, and the offers that let sellers sell your products, live in Mercur. The connector moves exactly what each side needs: offers and seller products flow into Magento, and your taxonomy and, optionally, your products flow into Mercur.++| Flow | Direction | Task | Triggered by |+| --- | --- | --- | --- |+| Sellers | Mercur → Magento | `sellers` | `seller.*` webhooks, every 15 minutes |+| Offers and their prices | Mercur → Magento | `offers` | `offer.*` webhooks, every 5 minutes |+| Seller products | Mercur → Magento | `products` | `product.published` webhook, hourly |+| Categories and attributes | Magento → Mercur | `taxonomy` | Saving a category or attribute, the full resync, the CLI |+| Your products | Magento → Mercur | `product_push` | Saving or deleting a product, every hour at :30, when it's on |++## Sellers++The seller mirror holds what the storefront shows about a seller: name, handle, description, logo, banner, city, country, premium flag, default lead time and closure window. It's listed under **Mercur → Sellers** in the Magento admin.++A seller's offers are sellable only while the seller is `open` and not inside its `closed_from`–`closed_to` window. When a seller is suspended, terminated or deleted, the `seller.*` webhook triggers a seller sync, which turns their offers off and reindexes the SKUs they sold. When they're reopened, the offers come back the same way.++<Note>+ The closure window is checked when the seller syncs. A window that starts or ends without any change to the seller takes effect at the next full resync, 02:00 by default.+</Note>++Each selling seller also gets a [seller page](/resources/integrations/magento2/storefront#seller-pages).++## Offers++An offer is one seller's way to sell one variant. The offer mirror, under **Mercur → Offers**, carries:++- **The product SKU it sells**, which is how Magento finds the product page to show it on+- **The seller's own SKU**, condition and lead time+- **Stock**: the stocked minus reserved quantity across the seller's locations. An offer that doesn't manage inventory or allows backorders is always available+- **A price per website**, read from the Store API in that website's region, so Mercur price lists, quantity tiers and currency all apply. When a price list lowers the price, the original price is kept for a strike-through++### Matching offers to your products++An offer lands on the Magento product whose SKU equals the Mercur variant SKU. When your SKUs differ from the ones sellers use, match on a barcode instead:++1. Choose the attributes that hold your EAN, UPC or GTIN under **Mercur → Marketplace → Offers → Identifier attributes**.+2. Run a full offer sync: `bin/magento mercur:sync offers --full`.++An offer whose SKU is unknown to Magento is then attached to the product whose identifier matches the offer's EAN or UPC, or its variant's EAN, UPC or barcode. Numeric codes are compared without leading zeros, so a 12-digit UPC matches the same EAN-13 written with a leading `0`. The offer sync output reports how many offers were matched by identifier.++## The buy box++For every SKU and website, the `mercur_offer_product` indexer decides which way to buy is preselected. The candidates are:++- **Your own stock**, when the product has a price and is salable in Magento+- **Every available offer** of an open seller with a price on that website++The **Best offer rule** picks among them:++| Rule | Preselects |+| --- | --- |+| Lowest total price | The lowest unit price, yours or a seller's |+| Our own stock first | Your stock whenever it's in stock, then the cheapest offer |+| Premium sellers first | Offers from premium sellers, then the cheapest |++<Note>+ The rule compares unit prices. Seller shipping isn't known until checkout, so it isn't part of the comparison.+</Note>++A configurable product rolls up from its children: the cheapest child's best offer, the lowest and highest price across children, and the total offer count. Category pages and search results show the best price, or "From" the lowest one when there are several ways to buy.++The index reindexes the touched SKUs after every offer and seller sync, and a SKU when you save its product. Rebuild it by hand with `bin/magento indexer:reindex mercur_offer_product`.++## Your products, seller products, or both++| Situation | What the shopper gets |+| --- | --- |+| A product only you sell | A normal Magento product: your price, your stock, your carriers |+| A product only sellers sell | A product imported from Mercur. It's in stock while any offer is available, and every line is a seller line |+| A product you and sellers sell | One product page and one buy box. When you run out, the product stays buyable from sellers and stays visible in categories and search |++## Importing seller products++When a product a seller created is published in Mercur, the connector creates it in Magento so it can be shown and sold. Turn this off with **Import published seller products**.++The workflow starts when Mercur emits `product.published`, or on the hourly schedule.++1. The `products` task reads published products changed since its last run, with their variants, options and images.+2. Products that Magento pushed itself are skipped. Their source product is already here.+3. Each variant is matched by SKU, then by identifier. A variant that matches one of your own products isn't imported: the offers attach to your product instead.+4. A product with two or more variants and global variant axes becomes a **configurable product**. The connector creates any missing axis attribute in the **Marketplace** attribute group, and each variant becomes a child that is Not Visible Individually. Otherwise every variant becomes a standalone simple product.+5. Name, description, websites, visibility and attribute values are written at the default scope. A global Mercur attribute whose handle matches a Magento attribute code is written to that attribute, and its options are created when missing. Everything else is kept as JSON in **Seller attributes** (`mercur_scoped_attributes`).+6. Images are downloaded into the media gallery when **Import product images** is on. The first one gets the base, small and thumbnail roles unless you already set them. Each image is named after a hash of its source URL, so a later run adds new images, removes ones Mercur dropped and leaves images you added in Magento untouched.+7. Stock follows the offers. An imported product is in stock while any offer for it is available on a selling website.++Imported products carry **Imported from Mercur** (`mercur_product`), their Mercur product and variant ids, and are never pushed back. Their price in Magento is `0`, because every line is priced from the offer the shopper picks.++When a product is rejected in Mercur, the `product.rejected` webhook disables it in Magento. It isn't deleted, so past orders keep their product.++<Tip>+ A product whose variant axis is product-scoped (an inline attribute in Mercur) has no Magento attribute to configure on, so its variants are imported as simple products. The process output says so. Use a global attribute as the axis to get a configurable.+</Tip>++## Pushing your taxonomy++Sellers create products in your categories and with your attributes, so Mercur needs both. The `taxonomy` task pushes:++- **Categories** below the root, in tree order. Each is matched by handle, the slug of its URL key. Name, description, active flag, position and parent are kept in sync, and the Magento id and path are stored in `metadata`.+- **Attributes** in the **Marketplace** attribute group of the configured attribute set. Each becomes a global Mercur attribute with the attribute code as its handle, and its options become values. On later runs, missing values are added.++Magento input types map to Mercur attribute types:++| Magento | Mercur |+| --- | --- |+| Dropdown | `single_select` |+| Multiple select | `multi_select` |+| Yes/No | `toggle` |+| Text field, text area | `text` |+| Price, weight | `unit` |+| A global dropdown used by configurables | `multi_select`, as a variant axis |++Saving a category or an attribute queues a taxonomy push. Run it by hand with `bin/magento mercur:sync taxonomy`.++## Pushing your products++Sellers can only make offers on products that exist in Mercur. With **Push operator products** on, the connector creates your Magento products in Mercur so sellers can list offers against them.++The workflow starts when you save a product, or on the hourly schedule.++1. The `product_push` task reads simple, virtual and configurable products changed since its last run. A child of a configurable is pushed through its parent, so one Mercur product carries all its variants.+2. Each product is looked up in Mercur by variant SKU. If a seller's product already uses the SKU, it's left alone and the output says so.+3. A new product is created with its title, description, URL key as handle, weight, images, categories and marketplace attributes. Its status is `published` when the Magento product is enabled, `draft` otherwise. Its `metadata.source` is `magento`, with the Magento id and SKU.+4. An existing product pushed earlier is updated, and new variants are added.++Prices and stock aren't pushed. You keep selling your own stock through Magento, and sellers attach their own price and stock through offers.++Deleting a product in Magento moves its Mercur product back to `draft`. It isn't deleted, so existing offers and past orders keep their variant.++<Warning>+ Push your taxonomy before your products. A product's categories and attributes are linked to their Mercur counterparts, and the push can't link what doesn't exist yet. The full resync runs `taxonomy` before `product_push` for this reason.+</Warning>diff --git a/apps/docs/resources/integrations/magento2/configuration.mdx b/apps/docs/resources/integrations/magento2/configuration.mdxnew file mode 100644index 000000000..f377570d2--- /dev/null+++ b/apps/docs/resources/integrations/magento2/configuration.mdx@@ -0,0 +1,229 @@+---+title: "Configure the Magento 2 connector"+sidebarTitle: "Configuration"+description: "Every setting of the connector on both sides: the Mercur plugin, API keys and their permissions, the webhook endpoint, and each field under Stores → Configuration → Mercur."+---++The connector is configured in two places. Mercur needs the plugin, a payment provider on the right region and a webhook endpoint. Magento holds everything else under **Stores → Configuration → Mercur → Marketplace**, with the API credentials, sync schedules and storefront behavior.++## Credentials and where they live++Three secrets connect the two systems. Each one is created on one side and stored on the other:++| Secret | Created in | Stored in | Used for |+| --- | --- | --- | --- |+| Admin API key | Mercur, **Settings → Secret API Keys** | Magento, `mercur/general/api_key`, encrypted | Every Admin API call from Magento |+| Publishable API key | Mercur, **Settings → Publishable API Keys** | Magento, `mercur/general/publishable_key`, encrypted | The Mercur cart behind checkout, offer prices |+| Webhook signing secret | Mercur, when the endpoint is created | Magento, `mercur/webhook/secret`, encrypted | Verifying the `x-mercur-signature` of every webhook |++Magento encrypts all three with its own crypt key and masks them in `var/log/mercur.log`, together with cookies and any `password`, `token` or `secret` field in a logged body.++<Warning>+ Mercur shows the signing secret once, in the response that creates the endpoint. Lists and lookups never return it. If you lose it, create a new endpoint, paste its secret into Magento and delete the old one.+</Warning>++## Mercur++### Plugin and payment provider++The plugin takes no options. Register it, and register its payment provider with the id `external`, which Medusa exposes as `pp_external_external`:++```ts medusa-config.ts+module.exports = withMercur({+ plugins: [+ { resolve: "@mercurjs/magento2-connector-plugin", options: {} },+ ],+ modules: [+ {+ resolve: "@medusajs/medusa/payment",+ options: {+ providers: [+ {+ resolve: "@mercurjs/magento2-connector-plugin/providers/payment-external",+ id: "external",+ },+ ],+ },+ },+ ],+})+```++Then add `pp_external_external` to the payment providers of every region a Magento website sells in. The provider records the payment Magento collected and never charges anyone, so it's safe to enable next to a real provider.++### API key permissions++If your project runs the roles module, bind the admin API key to a role that holds these permissions and nothing else. Without a roles module, an admin API key has full access.++| Permission | Right | Used for |+| --- | --- | --- |+| `integrations` | `edit` | Capture, cancel and refund calls, and the connection check |+| `sellers` | `view` | The seller mirror |+| `offers` | `view` | The offer mirror |+| `products` | `view` | Importing published seller products. Needs `edit` when **Push operator products** is on |+| `product_categories` | `edit` | Pushing your categories |+| `product_attributes` | `edit` | Pushing your marketplace attributes and their values |+| `orders` | `view` | Reading seller orders for fulfillment, cancellation and refund sync |++A higher right includes the lower ones: `edit` grants `view`.++### Webhook endpoint++Create the endpoint under **Settings → Magento → Add endpoint**:++| Field | Value |+| --- | --- |+| Endpoint URL | `https://your-magento-store.com/mercur/webhook` |+| Description | Optional, shown instead of the URL in the admin |+| Events | Keep all selected |++The connector needs the offer, seller and product events to keep the mirror current, and the order, shipment, delivery, return and refund events to keep orders in step. An event Magento has no handler for is acknowledged and ignored, so subscribing to everything is safe.++From the endpoint page you can pause and resume deliveries, read every attempt with its response, and redeliver any of them. You can also manage endpoints through the API: see [Mercur admin routes](/resources/integrations/magento2/reference#mercur-admin-routes).++### Cart channel++Magento sets `metadata.channel` on every Mercur cart it creates, `magento` by default. Mercur copies it onto the order group and each seller order, and **Settings → Magento** counts order groups with `channel: "magento"` as **Orders from Magento (24h)**. Keep the default unless you have a reason to tell several storefronts apart.++## Magento++Every field lives under **Stores → Configuration → Mercur → Marketplace**. The scope column says where a value can differ: **D** default, **W** website, **S** store view.++### Connection++| Field | Path | Scope | Default | Description |+| --- | --- | --- | --- | --- |+| Enabled | `mercur/general/enabled` | D W S | No | Turns the connector on for this scope |+| Mercur API URL | `mercur/general/api_url` | D W S | `http://localhost:9000` | Base URL of the Mercur API. A trailing `/` is trimmed |+| Admin API key | `mercur/general/api_key` | D W S | | Secret admin API key. Encrypted |+| Publishable API key | `mercur/general/publishable_key` | D W S | | Publishable key of the sales channel. Encrypted |+| Mercur sales channel ID | `mercur/general/sales_channel_id` | D W S | | Sales channel of the Mercur carts this scope creates |+| Mercur region ID | `mercur/general/region_id` | D W S | | The region whose prices this website shows. A website sells offers only when it has one |+| Channel | `mercur/general/channel` | D W | `magento` | Written to `metadata.channel` of every Mercur cart |+| Request timeout (seconds) | `mercur/general/timeout` | D W | `15` | Timeout of every Mercur API call |+| Retries | `mercur/general/retries` | D W | `2` | Retries on a network error, `429`, `500`, `502`, `503` or `504`. Only reads and deletes are retried |+| Retry delay (ms) | `mercur/general/retry_delay_ms` | D W | `500` | First retry delay. It doubles on every further attempt, with up to 50% jitter |+| API log level | `mercur/general/log_level` | D W S | Errors only | `Off`, `Errors only`, `Every request` or `Every request with bodies`. Written to `var/log/mercur.log` |++**Test connection** checks the saved values of the scope you're editing. It calls `GET /admin/magento/status` with the admin key, then looks up the region when one is set.++### Offers++| Field | Path | Scope | Default | Description |+| --- | --- | --- | --- | --- |+| Best offer rule | `mercur/offers/best_offer_rule` | D W | Lowest total price | Which way to buy a SKU is preselected. See [the buy box](/resources/integrations/magento2/catalog-and-offers#the-buy-box) |+| Label for your own stock | `mercur/offers/operator_label` | D W S | `Sold by us` | Shown on the product page row for your own stock |+| Identifier attributes | `mercur/offers/identifier_attributes` | D | | Product attributes that hold an EAN, UPC or GTIN. Offers and seller products are matched to your products through them when the SKUs differ. Run a full offer sync after changing it |++The three rules are:++| Value | Label | Preselects |+| --- | --- | --- |+| `lowest_total_price` | Lowest total price | The cheapest unit price, yours or a seller's |+| `operator_first` | Our own stock first | Your own stock whenever it's in stock, then the cheapest seller |+| `premium_first` | Premium sellers first | Premium sellers, then the cheapest |++### Delivery estimates++| Field | Path | Scope | Default | Description |+| --- | --- | --- | --- | --- |+| Show estimated delivery | `mercur/delivery/enabled` | D W | Yes | Shows "Arrives …" on offers, in the cart and at checkout |+| Order cut-off time | `mercur/delivery/cutoff_time` | D W | `14:00` | `HH:MM` in the store timezone. Orders after it count from the next business day |+| Business days | `mercur/delivery/business_days` | D W | Monday to Friday | Days that count for lead time and transit |+| Minimum transit days | `mercur/delivery/transit_days_min` | D W | `1` | Default transit time, low end |+| Maximum transit days | `mercur/delivery/transit_days_max` | D W | `3` | Default transit time, high end |++A Mercur shipping option can override both transit values through `data.transit_days_min` and `data.transit_days_max`. Lead time comes from the offer's `leadtime_to_ship`, or the seller's `default_leadtime_to_ship`.++### Checkout++| Field | Path | Scope | Default | Description |+| --- | --- | --- | --- | --- |+| Seller shipping prices include tax | `mercur/checkout/shipping_prices_include_tax` | D W S | No | Set to Yes when sellers quote gross shipping prices. Seller shipping is taxed with the shipping tax class from **Sales → Tax** |+| Remove unavailable seller lines automatically | `mercur/checkout/auto_remove_unavailable` | D W S | Yes | Yes drops a line whose offer was withdrawn and tells the shopper. No keeps it and blocks checkout until the shopper removes it |++### Orders++| Field | Path | Scope | Default | Description |+| --- | --- | --- | --- | --- |+| Create in Mercur when the order status is | `mercur/order/auto_create_statuses` | D W S | `pending`, `processing` | The order is sent once it's committed in one of these statuses. Leave out `pending` to wait for payment |+| Leave seller lines to the sellers | `mercur/order/lock_seller_shipping` | D W S | Yes | Keeps seller lines out of shipments created in Magento, from the admin or the REST ship endpoint. The connector records a shipment for each fulfillment Mercur reports |++### Webhooks++| Field | Path | Scope | Default | Description |+| --- | --- | --- | --- | --- |+| Signing secret | `mercur/webhook/secret` | D | | The secret Mercur showed when you created the endpoint. Encrypted |+| Maximum event age (seconds) | `mercur/webhook/max_age_sec` | D | `0` | Events whose `created_at` is older are acknowledged and ignored. `0` turns the check off |++The webhook settings exist at the default scope only, so one Magento installation has one endpoint.++### Catalog++| Field | Path | Scope | Default | Description |+| --- | --- | --- | --- | --- |+| Marketplace attribute group | `mercur/catalog/attribute_group` | D | `Marketplace` | Attributes in this group are pushed to Mercur as global attributes |+| Attribute set for imported products | `mercur/catalog/attribute_set_id` | D | `4` (Default) | Attribute set of imported seller products, and the set whose group is pushed |+| Import published seller products | `mercur/catalog/import_products` | D | Yes | Creates Magento products for seller products published in Mercur |+| Push operator products | `mercur/catalog/export_products` | D | No | Pushes your own products to Mercur so sellers can list offers on them. Push the taxonomy first |+| Status of imported products | `mercur/catalog/imported_product_status` | D | Enabled | |+| Visibility of imported products | `mercur/catalog/imported_product_visibility` | D | Catalog, Search | Children of an imported configurable are always Not Visible Individually |+| Websites for imported products | `mercur/catalog/website_ids` | D | | Leave empty to use every website with a region |+| Import product images | `mercur/catalog/import_images` | D | Yes | Downloads seller product images into the media gallery |+| Maximum image size (MB) | `mercur/catalog/image_max_size_mb` | D | `10` | Larger images are skipped and counted in the process output |+| Image download timeout (seconds) | `mercur/catalog/image_timeout_sec` | D | `20` | |++### Synchronisation++All schedules are cron expressions in the server timezone.++| Field | Path | Scope | Default | Runs |+| --- | --- | --- | --- | --- |+| Sellers schedule (cron) | `mercur/sync/sellers_cron` | D | `*/15 * * * *` | Seller delta |+| Offers delta schedule (cron) | `mercur/sync/offers_cron` | D | `*/5 * * * *` | Offer delta and prices |+| Published products schedule (cron) | `mercur/sync/products_cron` | D | `0 * * * *` | Seller product import |+| Operator product push schedule (cron) | `mercur/sync/product_push_cron` | D | `30 * * * *` | Product push, when it's on |+| Full resync schedule (cron) | `mercur/sync/full_cron` | D | `0 2 * * *` | Everything, from scratch |+| Refund fallback schedule (cron) | `mercur/sync/refunds_cron` | D | `*/15 * * * *` | Refunds whose webhook didn't arrive |+| Order retry schedule (cron) | `mercur/sync/order_retry_cron` | D | `*/10 * * * *` | Orders not yet sent or captured |+| Page size | `mercur/sync/page_size` | D W | `100` | Records per Admin API page |++### Processes++| Field | Path | Scope | Default | Description |+| --- | --- | --- | --- | --- |+| Timeout (seconds) | `mercur/process/timeout_sec` | D | `3600` | A running process with no output for this long is marked as timed out |+| Maximum attempts | `mercur/process/max_attempts` | D | `3` | Attempts of a process that asks to retry later |+| Keep history (days) | `mercur/process/history_days` | D | `30` | Finished processes older than this are deleted daily |++### Marketplace carrier++Under **Stores → Configuration → Sales → Delivery Methods → Mercur marketplace**:++| Field | Path | Scope | Default | Description |+| --- | --- | --- | --- | --- |+| Enabled | `carriers/mercur/active` | D W | Yes | |+| Title | `carriers/mercur/title` | D W S | `Marketplace` | |+| Method name | `carriers/mercur/name` | D W S | `Shipped by the sellers` | |++The carrier is offered only when every line in the cart comes from a seller, at a price of zero. Each seller's own shipping is charged in the **Seller shipping** total.++## Several websites++A website sells offers when the connector is enabled for it and it has a **Mercur region ID**. Each website is priced from its own region, including Mercur price lists, so a store with a US and an EU website needs two regions and two website-scoped region IDs.++<Warning>+ Each website's base currency must match its region's currency. Offers with no price in that currency are skipped, and the log shows `Offer {id} has no {CURRENCY} price in region {region}`.+</Warning>++## When the connection check fails++| Message | Cause |+| --- | --- |+| Save the API URL and admin API key first. | The scope you're editing has no saved URL or key. Save, then test |+| Mercur rejected the admin API key (HTTP 401). | The key is wrong, revoked, or not a secret admin key |+| Mercur rejected the admin API key (HTTP 403). | The key's role misses `integrations:view`. See [API key permissions](#api-key-permissions) |+| Mercur answered with an error: … | The plugin isn't installed, so `/admin/magento/status` doesn't exist, or the API failed |+| Connection failed: … | Magento can't reach the API URL. Check DNS, TLS and firewalls from the Magento host |+| Region `reg_...` was not found. | The region ID is wrong for this scope |+| No region id set for this scope. | Expected at the default scope. Switch to the website and test again |diff --git a/apps/docs/resources/integrations/magento2/orders-and-payments.mdx b/apps/docs/resources/integrations/magento2/orders-and-payments.mdxnew file mode 100644index 000000000..097856e6e--- /dev/null+++ b/apps/docs/resources/integrations/magento2/orders-and-payments.mdx@@ -0,0 +1,133 @@+---+title: "Orders and payments"+sidebarTitle: "Orders and payments"+description: "How a Magento order becomes one Mercur order per seller, when the payment is captured, how seller shipments reach Magento, and how refunds move in both directions."+---++Magento collects the money, and Mercur keeps track of whose it is. The shopper pays once through your Magento payment method. Mercur records that payment on the `pp_external_external` provider, splits it across one order per seller and computes commission. No money moves through Mercur at checkout, so Mercur only follows what Magento reports: an authorization when the order is sent, a capture when it's invoiced, a refund when it's credited.++## The external payment++Each Magento order with seller lines has one payment in Mercur, held by the order group's cart. Its status follows the Magento order:++| Magento | Mercur payment | Route Magento calls |+| --- | --- | --- |+| Order committed in a configured status | Authorized | `POST /store/carts/:id/complete` |+| Invoice paid | Captured, then split per seller order | `POST /admin/magento/order-groups/:id/payments/capture` |+| Order canceled before capture | Canceled, every seller order canceled | `POST /admin/magento/order-groups/:id/payments/cancel` |+| Credit memo on seller lines | Refund recorded on the seller order | `POST /admin/magento/orders/:id/refunds/external` |++The Magento order number is the payment's reference, and Magento's payment method is stored with it.++## Send the order to Mercur++The workflow starts when Magento commits an order that has seller lines.++1. Magento checks the order's status against **Create in Mercur when the order status is**, `pending` and `processing` by default. Remove `pending` to wait until the payment is confirmed.+2. It adds an authorized payment session on `pp_external_external` to the Mercur cart it built during checkout, and completes the cart.+3. Mercur splits the cart into an order group with one order per seller and computes their commission lines.+4. Magento stores the order group on the order and each seller order on its lines, sets every seller line to `not_fulfilled`, and adds the comment `Marketplace order group {number} created in Mercur.`++Your own lines are never sent. A cart's channel, `magento` by default, is copied onto the order group and every seller order as `metadata.channel`.++If Mercur doesn't answer, the Magento order still succeeds. The comment "Marketplace order could not be created in Mercur: …" explains why, and the `order_retry` process sends it on its next run, every 10 minutes by default. **Send to marketplace** on the order view sends it at once.++## Capture the payment++The workflow starts when an invoice on the order is paid.++1. Magento calls the capture route for the order group.+2. Mercur captures the external payment once and splits it across the seller orders. Calling it again is a no-op.+3. Magento adds the comment "Marketplace payment captured in Mercur."++Capture confirms the whole order group on the first paid invoice. That invoice also carries all the seller shipping that isn't invoiced yet.++A capture that fails is retried by `order_retry`, and the comment says so. When your payment method captures at placement, the invoice is paid before the order reaches Mercur. `order_retry` then captures right after it's sent.++Mercur splits the payment across seller orders only once it's captured, so what each seller is owed follows money you actually collected. See [the payout pipeline](/platform/payout/concepts/payout-pipeline) for how transfers to sellers are triggered.++## Cancel before capture++The workflow starts when you cancel a Magento order that hasn't been captured.++1. Magento calls the cancel route.+2. Mercur cancels every seller order in the group and voids the authorization.+3. Magento adds the comment "Marketplace payment authorization released in Mercur."++After capture the payment can't be canceled. Refund the order with a credit memo instead.++## Fulfillment++Sellers ship their own lines from the vendor panel. Magento records what they report.++The workflow starts when a seller creates, ships, delivers or cancels a fulfillment.++1. Mercur sends `order.fulfillment_created`, `shipment.created`, `delivery.created` or `order.fulfillment_canceled`.+2. Magento reads the seller order with its fulfillments and tracking labels.+3. For each fulfillment that has shipped and isn't recorded yet, it creates a Magento shipment of those lines, with the tracking numbers and a customer-visible comment linking to the tracking pages. The customer is notified the usual way.+4. Each seller line's marketplace status is updated from its quantities: `fulfilled`, `partially_shipped`, `shipped` or `delivered`.++Partial and multi-parcel deliveries become one Magento shipment each, as they happen. The order stays in **Processing** until every fulfillment is recorded.++### Seller lines are shipped by sellers++With **Leave seller lines to the sellers** on, the default, seller lines can't be shipped from the Magento admin or the REST ship endpoint. Your own lines ship as usual. The lock covers shipping only: invoices, cancellations and credit memos work on seller lines as before.++### Resync by hand++**Resync marketplace status** on the order view reads every seller order again and records anything missing. Use it after a webhook outage that lasted longer than Mercur's retries.++## When a seller cancels or refuses++The workflow starts when a seller order is canceled in Mercur.++1. Mercur sends `order.canceled`.+2. Magento sets the seller's lines to `refused` when the seller canceled, or `canceled` when the operator did, and adds an order comment.+3. If those lines were invoiced, Magento issues a credit memo for them and that seller's shipping, refunding the shopper.++## Returns++Return events, `order.return_requested` and `order.return_received`, update the lines to **Return requested** and **Returned** and add an order comment. They don't move money. The refund comes separately, when the seller or operator refunds the order in Mercur.++## Refunds++Refunds can start on either side. Each is executed where the money is, and recorded on the other side, so commission and the seller's balance stay right.++### Refund from Magento++The workflow starts when you create a credit memo that includes seller lines or seller shipping.++1. For each seller order on the credit memo, Magento adds up the refunded seller lines, including tax and minus discounts.+2. It splits the refunded seller shipping across sellers by what each one charged.+3. It records each amount on the seller order through the external refund route, with the credit memo number as the reference.+4. Mercur records the refund on the captured payment, tagged `metadata.source: "external"`, and emits `order.refund_recorded`.++<Warning>+ A report that fails is logged to `var/log/mercur.log` as `Mercur refund report failed` and isn't retried. Record the missing amount on the seller order with `POST /admin/magento/orders/:id/refunds/external`, or the seller's balance will include money you already refunded.+</Warning>++### Refund from Mercur++The workflow starts when a seller or an operator refunds a seller order in Mercur.++1. Mercur records the refund. It has moved no money, so the plugin emits `order.refund_requested` with the order, amount and refund id.+2. Magento issues an adjustment credit memo for the amount on the Magento order. It refunds online through your payment method when the invoice was captured online, and offline otherwise.+3. The credit memo stores the Mercur refund id, so a repeated webhook doesn't refund twice, and it isn't reported back.++When a credit memo isn't possible, the order gets the comment `Mercur refund {id} of {amount} could not be refunded automatically. Refund it manually.`++If the webhook never arrives, the `refunds` process finds the refund within 15 minutes. It checks seller orders on Magento orders updated in the last 30 days that aren't closed or canceled.++## In the Magento admin++Every order with seller lines has a **Marketplace** section: the order group, and per seller the seller order, items, seller shipping, status and tracking. Each item has a marketplace status column, and the order grid has a **Marketplace order group** column.++Three buttons on the order view cover anything that needs a push by hand:++| Button | Shown when | Does |+| --- | --- | --- |+| Send to marketplace | The order isn't in Mercur yet | Sends it now, whatever its status |+| Capture marketplace payment | The order is paid and not yet captured in Mercur | Confirms the capture |+| Resync marketplace status | The order is in Mercur | Reads every seller order again and records missing shipments and statuses |++The buttons need the **Mercur → Order actions** ACL resource.diff --git a/apps/docs/resources/integrations/magento2/overview.mdx b/apps/docs/resources/integrations/magento2/overview.mdxnew file mode 100644index 000000000..bb8f0a54c--- /dev/null+++ b/apps/docs/resources/integrations/magento2/overview.mdx@@ -0,0 +1,93 @@+---+title: "Magento 2"+sidebarTitle: "Overview"+description: "Sell Mercur marketplace offers from a Magento 2 or Adobe Commerce store, next to your own products, with one checkout and one payment."+---++The Magento 2 connector turns a store you already run into a marketplace. Shoppers keep using your Magento storefront, cart and checkout. Sellers list offers in Mercur, and those offers appear on your product pages next to your own stock. One checkout can mix your products and products from several sellers, and the shopper pays once.++After checkout, Magento keeps the order and the payment. Mercur splits the seller lines into one order per seller, computes commission and tracks what each seller owes and is owed.++## Who owns what++| | Magento | Mercur |+| --- | --- | --- |+| Storefront, cart, checkout | ✓ | |+| Payment, invoices, credit memos | ✓ | |+| Your own products, prices, stock, carriers | ✓ | |+| Sellers and their onboarding | | ✓ |+| Offers: seller SKU, price, stock, shipping | | ✓ |+| One order per seller, fulfillment, returns | | ✓ |+| Commission and payouts | | ✓ |++Magento never sees a seller's stock levels as its own, and Mercur never charges the shopper. Each side reads what it needs from the other through the API and webhooks.++## What you get++- **A buy box on every product page**: your own stock and every active seller offer, with per-website prices, price list strike-through, quantity tiers and an estimated delivery date+- **Seller-only products**: published seller products are imported as simple or configurable products, with images, and stay buyable while any offer is in stock+- **Your catalog in Mercur**: your own products can be pushed to Mercur so sellers can list offers against them, matched by SKU or by EAN, UPC or GTIN+- **One checkout**: lines grouped by seller, a shipping choice per seller and "Sold by" on every line, and a "Seller shipping" total on the cart, order, invoice and emails+- **One payment, split after capture**: the order is created in Mercur with the payment authorized, and the capture is confirmed when Magento invoices+- **Seller fulfillment**: every shipment a seller creates becomes a Magento shipment with tracking, including partial and multi-parcel deliveries+- **Refunds in both directions**: a Magento credit memo is reported to Mercur, and a refund started in Mercur becomes a Magento credit memo+- **Seller pages** at `/seller/{handle}`, and GraphQL and REST support for headless storefronts++## Two packages++The integration ships as two packages, one on each side:++| Package | Installed in | Adds |+| --- | --- | --- |+| [`@mercurjs/magento2-connector-plugin`](https://www.npmjs.com/package/@mercurjs/magento2-connector-plugin) | Your Mercur API | Signed outbound webhooks, the `pp_external_external` payment provider, capture, cancel and refund routes, and the **Settings → Magento** page |+| [`mercurjs/magento2-connector`](https://github.com/mercurjs/magento2-connector) | Your Magento root | Nine `Mercur_*` modules that mirror sellers and offers, run checkout against Mercur and keep orders in step |++## Compatibility++| Platform | Version |+| --- | --- |+| Magento Open Source | 2.4.4 and later |+| Adobe Commerce | 2.4.4 and later |+| PHP | 8.1, 8.2, 8.3 |+| Mercur | 2.3.8 and later, with `@mercurjs/magento2-connector-plugin` |++Stores running Multi-Source Inventory enable one extra module, `Mercur_Inventory`.++## Not supported yet++- Buyer and seller messaging, order incidents and seller ratings+- Documents sellers attach to orders+- A third-party tax engine for seller lines. Magento taxes them with the product's tax class+- Mercur promotions. Magento cart price rules never apply to seller lines+- Shipping one order to several addresses++## Get started++<CardGroup cols={2}>+ <Card title="Quickstart" icon="rocket" href="/resources/integrations/magento2/quickstart">+ Connect a Magento store to Mercur and place a first mixed order.+ </Card>+ <Card title="Architecture" icon="sitemap" href="/resources/integrations/magento2/architecture">+ What runs on each side, how they sync and how an order travels.+ </Card>+ <Card title="Configuration" icon="sliders" href="/resources/integrations/magento2/configuration">+ Every setting on both sides, its scope and its default.+ </Card>+ <Card title="Reference" icon="book" href="/resources/integrations/magento2/reference">+ Scheduled jobs, CLI, webhook events, routes and the GraphQL schema.+ </Card>+</CardGroup>++## Guides++<CardGroup cols={3}>+ <Card title="Catalog and offers" icon="tags" href="/resources/integrations/magento2/catalog-and-offers">+ Sellers, offers, the buy box, product import and push.+ </Card>+ <Card title="Storefront" icon="store" href="/resources/integrations/magento2/storefront">+ Product page, cart, checkout, seller pages and GraphQL.+ </Card>+ <Card title="Orders and payments" icon="credit-card" href="/resources/integrations/magento2/orders-and-payments">+ Placement, capture, shipments, returns and refunds.+ </Card>+</CardGroup>diff --git a/apps/docs/resources/integrations/magento2/quickstart.mdx b/apps/docs/resources/integrations/magento2/quickstart.mdxnew file mode 100644index 000000000..85803ecd3--- /dev/null+++ b/apps/docs/resources/integrations/magento2/quickstart.mdx@@ -0,0 +1,195 @@+---+title: "Magento 2 quickstart"+sidebarTitle: "Quickstart"+description: "Install both halves of the connector, connect Magento to Mercur, run the first sync and place a first order that mixes your products with a seller's."+---++By the end of this guide a seller's offer shows on one of your Magento product pages, and one checkout buys it together with your own stock. Plan for about 30 minutes.++<Note>+ You need a running Mercur project on 2.3.8 or later, and a Magento 2.4.4+ store with [cron running](https://experienceleague.adobe.com/en/docs/commerce-operations/configuration-guide/cli/configure-cron-jobs). The connector does all background work from cron, so nothing syncs without it.+</Note>++Before you start, make sure you have:++- A Mercur region whose currency matches the base currency of the Magento website that will sell offers+- A Mercur sales channel for the Magento store+- At least one approved seller with an active offer in that region+- A public HTTPS URL for the Magento store that your Mercur API can reach++## Step 1: Install the plugin in Mercur++Add the plugin to your Mercur API:++```bash+bun add @mercurjs/magento2-connector-plugin+```++Register the plugin and its payment provider in `medusa-config.ts`:++```ts medusa-config.ts+module.exports = withMercur({+ // ...+ plugins: [+ { resolve: "@mercurjs/magento2-connector-plugin", options: {} },+ ],+ modules: [+ {+ resolve: "@medusajs/medusa/payment",+ options: {+ providers: [+ {+ resolve: "@mercurjs/magento2-connector-plugin/providers/payment-external",+ id: "external",+ },+ ],+ },+ },+ ],+})+```++Run the migrations and restart the API:++```bash+bunx medusa db:migrate+```++Open **Settings → Magento** in the Mercur admin. The **Payment provider** row shows `pp_external_external`. If it says **Not registered**, the provider block above isn't loaded.++## Step 2: Enable the payment provider on your region++The connector records the Magento payment on the `pp_external_external` provider. Open the region the Magento website sells in, edit it, and add **pp_external_external** to its payment providers.++<Warning>+ Without this the Mercur cart can't complete, and every Magento order with seller lines stays unsent.+</Warning>++## Step 3: Create the API keys++Magento needs two keys from Mercur:++- **A secret admin API key.** Create it under **Settings → Secret API Keys**. Magento reads sellers, offers and products with it, and confirms captures and refunds. If your project runs the roles module, give the key a role with the [permissions the connector needs](/resources/integrations/magento2/configuration#api-key-permissions). Without a roles module the key has full admin access, so store it like an admin password.+- **A publishable API key**, under **Settings → Publishable API Keys**, for the sales channel from the prerequisites. Magento builds the Mercur cart for each checkout with it.++Copy the ID of the region and the sales channel too. You'll paste all four values in the next steps.++## Step 4: Install the Magento package++In your Magento root, add the repository and require the package:++```bash+composer config repositories.mercur vcs https://github.com/mercurjs/magento2-connector+composer require mercurjs/magento2-connector:dev-main+```++Enable the modules and rebuild:++```bash+bin/magento module:enable Mercur_Core Mercur_Process Mercur_Connector \+ Mercur_OfferIndexer Mercur_Catalog Mercur_Settlement Mercur_Frontend Mercur_GraphQl+# Only on stores that run Multi-Source Inventory:+bin/magento module:enable Mercur_Inventory+bin/magento setup:upgrade+bin/magento setup:di:compile+bin/magento cache:flush+```++A **Mercur** menu now appears in the Magento admin, with **Sellers**, **Offers**, **Processes** and **Configuration**.++## Step 5: Connect Magento to Mercur++Open **Stores → Configuration → Mercur → Marketplace → Connection**. Set the API URL, both keys and the sales channel at the default scope. Then switch the scope to the website that sells offers and set its **Mercur region ID**:++| Field | Value |+| --- | --- |+| Enabled | Yes |+| Mercur API URL | `https://api.your-marketplace.com` |+| Admin API key | the secret key from step 3 |+| Publishable API key | the publishable key from step 3 |+| Mercur sales channel ID | `sc_...` |+| Mercur region ID | `reg_...`, set on the website |++Save, then click **Test connection**. A working setup answers with both lines:++```text+Connected to https://api.your-marketplace.com.+Region Europe (EUR).+```++<Tip>+ The check uses the saved values of the scope you're editing. Save before you test, and test once at the website scope so the region lookup runs.+</Tip>++## Step 6: Register the webhook++Mercur tells Magento about new offers, seller changes, shipments, returns and refunds through a signed webhook.++1. In the Mercur admin, open **Settings → Magento** and click **Add endpoint**.+2. Enter `https://your-magento-store.com/mercur/webhook` and keep every event selected.+3. Click **Create** and copy the **Signing secret**. It's shown once.+4. In Magento, paste it into **Stores → Configuration → Mercur → Marketplace → Webhooks → Signing secret**, at the default scope, and save.++To check it, edit any seller in Mercur. A `seller.updated` delivery appears under the endpoint's **Deliveries** as **Delivered**. If it shows **Retrying** with a `401`, the secret in Magento doesn't match.++The status card at the top of **Settings → Magento** now shows **Connected**.++## Step 7: Run the first sync++Mirror Mercur into Magento:++```bash+bin/magento mercur:sync taxonomy+bin/magento mercur:sync full+```++`taxonomy` pushes your categories and marketplace attributes to Mercur, so seller products can use them. `full` imports sellers, offers and published seller products, and prices each offer for every website that has a region.++Check the result in the Magento admin:++- **Mercur → Sellers** lists your sellers+- **Mercur → Offers** lists their offers, with a price and the websites that sell them+- **Mercur → Processes** shows each step of the full resync as **Completed**, with its output++From now on cron keeps the mirror current, and webhooks trigger a delta sync within a minute of a change.++## Step 8: Place a test order++Open a product page on the storefront for a SKU with a seller offer. Under **Also sold by**, the seller's offer shows its price and estimated delivery.++1. Add the seller's offer to the cart, and one of your own products too.+2. Go to checkout. The seller's line sits in its own group with a shipping choice, and the totals show **Seller shipping**.+3. Place the order with any payment method.++In the Magento admin, the order's comments show:++```text+Marketplace order group 12 created in Mercur.+```++The **Marketplace** section of the order lists the seller's order with its status. In the Mercur admin, the order group appears under **Orders** and the seller sees their order in the vendor panel.++Invoice the order in Magento. A second comment confirms the capture:++```text+Marketplace payment captured in Mercur.+```++The seller can now fulfill. When they ship, the shipment and its tracking number appear on the Magento order.++## Next steps++<CardGroup cols={2}>+ <Card title="Configuration" icon="sliders" href="/resources/integrations/magento2/configuration">+ The best offer rule, delivery estimates, product push and every other setting.+ </Card>+ <Card title="Orders and payments" icon="credit-card" href="/resources/integrations/magento2/orders-and-payments">+ What happens on invoice, cancel, shipment and refund.+ </Card>+ <Card title="Architecture" icon="sitemap" href="/resources/integrations/magento2/architecture">+ How the two sides stay in step, and what happens when one is down.+ </Card>+ <Card title="Reference" icon="book" href="/resources/integrations/magento2/reference">+ Cron jobs, CLI commands and webhook events.+ </Card>+</CardGroup>diff --git a/apps/docs/resources/integrations/magento2/reference.mdx b/apps/docs/resources/integrations/magento2/reference.mdxnew file mode 100644index 000000000..bac18603f--- /dev/null+++ b/apps/docs/resources/integrations/magento2/reference.mdx@@ -0,0 +1,328 @@+---+title: "Magento 2 reference"+sidebarTitle: "Reference"+description: "Scheduled jobs, background tasks, CLI commands, webhook events and signatures, Mercur admin routes, Magento events, the GraphQL schema and the database tables the connector adds."+---++## Scheduled jobs++### Magento++All jobs run in Magento's `default` cron group. Each one queues a [process](#tasks), and `mercur_process_run_pending` runs it within a minute. The sync jobs queue nothing while the connector is disabled everywhere.++| Job | Default schedule | Config path | Queues | Recommended |+| --- | --- | --- | --- | --- |+| `mercur_process_run_pending` | Every minute | | Runs up to 10 due processes | Leave as is |+| `mercur_sync_offers` | `*/5 * * * *` | `mercur/sync/offers_cron` | `offers` | Under 15 minutes |+| `mercur_sync_sellers` | `*/15 * * * *` | `mercur/sync/sellers_cron` | `sellers` | Under 1 hour |+| `mercur_sync_products` | `0 * * * *` | `mercur/sync/products_cron` | `products` | Under 1 day |+| `mercur_push_products` | `30 * * * *` | `mercur/sync/product_push_cron` | `product_push` | Off-peak when your catalog is large |+| `mercur_retry_orders` | `*/10 * * * *` | `mercur/sync/order_retry_cron` | `order_retry` | Under 1 hour |+| `mercur_poll_refunds` | `*/15 * * * *` | `mercur/sync/refunds_cron` | `refunds` | Under 1 hour |+| `mercur_sync_full` | `0 2 * * *` | `mercur/sync/full_cron` | `full` | Daily, off-peak |+| `mercur_process_clear_history` | `0 3 * * *` | | Deletes finished processes older than **Keep history** | Leave as is |++### Mercur++The plugin adds two scheduled jobs to your Mercur API:++| Job | Schedule | Does |+| --- | --- | --- |+| `retry-magento-webhook-deliveries` | Every minute | Sends up to 200 deliveries that are queued or retrying and due |+| `prune-magento-webhook-deliveries` | `0 3 * * *` | Deletes delivered deliveries older than 30 days. Failed and abandoned ones are kept |++## Tasks++Every unit of background work in Magento is a process running one task. Run any task with `bin/magento mercur:sync <task>`, or from **Mercur → Processes → Run task**.++| Task | Name | Does | Parameters |+| --- | --- | --- | --- |+| `sellers` | Import sellers | Mirrors sellers changed since the last run, and turns their offers on or off | `full` |+| `offers` | Import offers | Mirrors offers changed since the last run and prices them for every selling website | `full` |+| `products` | Import published seller products | Creates and updates Magento products for published seller products | `full` |+| `taxonomy` | Push categories and attributes | Pushes categories and marketplace attributes to Mercur | |+| `product_push` | Push operator products | Pushes your own products to Mercur | `full`, `skus`, `archive` |+| `full` | Full resync | Queues `sellers`, `offers`, `taxonomy`, `product_push` and `products` with `full`, as child processes in that order | |+| `order_retry` | Retry marketplace order creation and payment capture | Sends orders that aren't in Mercur yet and confirms captures that failed, 50 of each per run | |+| `refunds` | Execute refunds started in Mercur | Executes Mercur refunds whose webhook didn't arrive | |++`full` ignores the delta cursor and, for offers, removes anything Mercur no longer returns. If Mercur returns no offers at all, nothing is removed.++### Process statuses++| Status | Meaning |+| --- | --- |+| `pending` | Queued |+| `pending_retry` | Asked to retry later. Waits 60 seconds, doubling up to an hour, until **Maximum attempts** |+| `processing` | Running. Locked by `hostname:pid` |+| `completed` | Finished |+| `error` | Failed, or out of attempts |+| `timeout` | No output for longer than **Timeout (seconds)** |+| `stopped` | Stopped from the admin |++A process queued while an identical one is `pending`, `pending_retry` or `processing` is merged into it.++## CLI++| Command | Does |+| --- | --- |+| `bin/magento mercur:sync` | Runs every due process now |+| `bin/magento mercur:sync <task> [--full]` | Queues the task, runs it now and prints its output. Exits non-zero unless it completes |+| `bin/magento mercur:process:run <id>` | Runs one pending process |+| `bin/magento mercur:process:clear-history [--days=N]` | Deletes finished processes older than `N` days, **Keep history** by default |++## Webhooks++### Delivery++Mercur posts every event to each active endpoint subscribed to it, with a 10-second timeout:++```http+POST /mercur/webhook HTTP/1.1+Content-Type: application/json+User-Agent: mercur-magento2-connector+x-mercur-event: offer.updated+x-mercur-delivery: mwhd_01JB8K3XQ0M7S2VYH4T6R9C5DE+x-mercur-signature: sha256=5f2b0c7e…++{+ "id": "mwhd_01JB8K3XQ0M7S2VYH4T6R9C5DE",+ "event": "offer.updated",+ "created_at": "2026-10-26T09:41:07.000Z",+ "data": { "id": "offer_01JB8K2Y7W3N0QF5E1A6H9TZXG" }+}+```++`data` is the event's own payload, usually `{ "id" }` of the record that changed. `shipment.created` and `delivery.created` also carry `fulfillment_id` and `order_id`.++A `2xx` answer marks the delivery **Delivered**. Anything else, or no answer, marks it **Retrying** and schedules the next attempt:++| Attempt | After the previous one |+| --- | --- |+| 2 | 1 minute |+| 3 | 5 minutes |+| 4 | 30 minutes |+| 5 | 2 hours |+| 6 | 12 hours |++After the sixth failure the delivery is marked **Gave up**. Every delivery can be sent again from the endpoint page or through the redeliver route.++### Signature++`x-mercur-signature` is `sha256=` followed by the hex HMAC-SHA256 of the raw request body, keyed with the endpoint's signing secret. There's no timestamp in the signature. To reject old events, set **Maximum event age** and Magento compares it with `created_at`.++Verify it before parsing the body:++<CodeGroup>+```php PHP+$expected = 'sha256=' . hash_hmac('sha256', $rawBody, $secret);+if (!hash_equals($expected, $request->getHeader('x-mercur-signature'))) {+ // 401+}+```++```ts Node.js+import { createHmac, timingSafeEqual } from "node:crypto"++const expected = "sha256=" + createHmac("sha256", secret).update(rawBody).digest("hex")+const valid =+ signature.length === expected.length &&+ timingSafeEqual(Buffer.from(signature), Buffer.from(expected))+```+</CodeGroup>++### Magento's answers++| Response | When |+| --- | --- |+| `200 {"received":true,"event":"…"}` | Handled, or no handler for the event |+| `200 {"received":true,"event":"…","duplicate":true}` | The `x-mercur-delivery` id was already processed |+| `200 {"received":true,"event":"…","stale":true}` | Older than **Maximum event age** |+| `400 {"error":"invalid json"}` | The body isn't JSON |+| `401 {"error":"invalid signature"}` | No signature, no secret configured, or a mismatch |+| `500 {"error":"handler failed"}` | A handler threw. The id is forgotten, so Mercur's retry runs again |++Processed delivery ids are kept in `mercur_webhook_event` for 30 days.++### Events++| Event | Magento does |+| --- | --- |+| `offer.created`, `offer.updated`, `offer.deleted` | Queues an `offers` delta |+| `seller.updated`, `seller.approved`, `seller.suspended`, `seller.unsuspended`, `seller.terminated`, `seller.unterminated` | Queues a `sellers` delta |+| `product.published` | Queues a `products` delta |+| `product.rejected` | Disables the imported product |+| `order.fulfillment_created`, `order.fulfillment_canceled`, `shipment.created`, `delivery.created` | Records shipments and updates line statuses for the seller order |+| `order.return_requested`, `order.return_received` | Updates line statuses and adds an order comment |+| `order.canceled` | Marks the seller's lines `refused` or `canceled` and credits what was invoiced |+| `order.refund_requested` | Issues an adjustment credit memo for the amount |+| `order_group.created`, `order.updated`, `order.refund_recorded`, `order.payment_captured` | Acknowledged, no action |++Payloads of the events the plugin emits:++| Event | `data` |+| --- | --- |+| `order.refund_requested` | `{ order_id, payment_id, refund_id, amount, currency_code, note }` |+| `order.refund_recorded` | `{ id, payment_id, amount, reference }`, where `id` is the seller order |+| `order.payment_captured` | `{ id, payment_id, reference }`, where `id` is the order group |++`order.refund_requested` is only emitted for payments on `pp_external_external`, and never for refunds Magento recorded itself.++## Mercur admin routes++The plugin adds these routes to your Mercur API. All need an admin session or secret API key, and the `integrations` permission at the right shown.++| Method | Path | Right | Does |+| --- | --- | --- | --- |+| `GET` | `/admin/magento/status` | `view` | Connection status, used by **Test connection** |+| `GET` | `/admin/magento/webhooks` | `view` | Lists endpoints. Filters: `id`, `is_active` |+| `POST` | `/admin/magento/webhooks` | `manage` | Creates an endpoint and returns its `secret`, once |+| `GET` | `/admin/magento/webhooks/:id` | `view` | Retrieves an endpoint, without its secret |+| `POST` | `/admin/magento/webhooks/:id` | `manage` | Updates `url`, `events`, `is_active`, `description`, `metadata` or `secret` |+| `DELETE` | `/admin/magento/webhooks/:id` | `manage` | Deletes an endpoint and its deliveries |+| `GET` | `/admin/magento/webhooks/:id/deliveries` | `view` | Lists deliveries. Filters: `status`, `event`, `created_at` |+| `POST` | `/admin/magento/webhooks/:id/deliveries/:delivery_id/redeliver` | `edit` | Sends a delivery again, whatever its status |+| `POST` | `/admin/magento/order-groups/:id/payments/capture` | `edit` | Captures the group's external payment. Body: `{ reference? }` |+| `POST` | `/admin/magento/order-groups/:id/payments/cancel` | `edit` | Cancels every seller order and voids the payment. Fails once captured |+| `POST` | `/admin/magento/orders/:id/refunds/external` | `edit` | Records a refund on a seller order's captured payment. Body: `{ amount, reference?, note? }` |++Create an endpoint through the API:++```bash+curl -X POST https://api.your-marketplace.com/admin/magento/webhooks \+ -u "$MERCUR_SECRET_API_KEY:" \+ -H "Content-Type: application/json" \+ -d '{+ "url": "https://your-magento-store.com/mercur/webhook",+ "events": ["offer.created", "offer.updated", "offer.deleted", "seller.updated"],+ "description": "Production store"+ }'+```++`GET /admin/magento/status` answers:++```json+{+ "payment_provider": { "id": "pp_external_external", "installed": true },+ "events": ["offer.created", "offer.updated", "…"],+ "webhooks": { "total": 1, "active": 1 },+ "deliveries": {+ "window_hours": 24,+ "delivered": 412,+ "failed": 0,+ "dead": 0,+ "pending": 0,+ "last_delivered_at": "2026-10-26T09:41:08.000Z"+ },+ "orders": { "channel": "magento", "last_24h": 37 }+}+```++### Delivery statuses++| Status | Shown as | Meaning |+| --- | --- | --- |+| `pending` | Queued | Created, not sent yet |+| `delivered` | Delivered | Answered with `2xx` |+| `failed` | Retrying | Failed, next attempt scheduled |+| `dead` | Gave up | Failed six times |++### External payment session data++The `data` Magento sends with the `pp_external_external` payment session. Another storefront can also pass `captured_at` to record a payment that is already settled.++| Field | Description |+| --- | --- |+| `reference` | The Magento order number |+| `amount`, `currency_code` | The Mercur cart total, seller lines and seller shipping, in the website's base currency |+| `authorized_at` | When Magento sent the order |+| `channel` | The cart channel, `magento` by default |+| `payment_method` | Magento's payment method code |++## Magento events++Observe these from your own module to extend the connector:++| Event | Data |+| --- | --- |+| `mercur_api_call_before` | `request`: `method`, `url`, `path`, `headers`, `body`, `store_id`. Headers can be changed |+| `mercur_api_call_after` | `request`, `status`, `body`, `duration_ms`, `attempt`, `exception` on a transport failure |+| `mercur_webhook_received` | `event_name`, `payload`. Changes to `payload` reach the handlers |+| `mercur_seller_imported` | `sellers`, `deleted`, `full` |+| `mercur_offer_mapped_before` | `offer`, `transport`. Set `skip` on `transport` to skip the offer |+| `mercur_offer_mapped_after` | `row`, which can be changed, and `offer` |+| `mercur_offers_imported` | `skus`, `full` |+| `mercur_cart_sync_before` | `quote`, `items`, which can be changed |+| `mercur_order_place_before` | `order`, `cart_id` |+| `mercur_order_place_after` | `order`, `cart_id`, `order_group_id`, `seller_orders` |+| `mercur_fulfillment_synced` | `order`, `seller_order_id`, `shipments_created` |+| `mercur_refund_reported` | `order`, `creditmemo`, `seller_order_id`, `refund_id`, `amount` |++Webhook handlers are registered in `di.xml` on `Mercur\Connector\Model\Webhook\Dispatcher`, keyed by event name. A handler under `*` runs for every event.++## GraphQL++| Addition | Type |+| --- | --- |+| `ProductInterface.mercur_offers` | `[MercurOffer]`, cheapest first. A configurable returns its variants' offers |+| `ProductInterface.mercur_buy_box` | `MercurBuyBox`: `best_offer_id`, `best_seller_id`, `best_price`, `min_price`, `max_price`, `offer_count`, `operator_available` |+| `CartItemInput.mercur_offer_id` | Buys the line from this offer |+| `CartItemInterface.mercur_offer` | `MercurCartItemOffer`: `offer_id`, `seller`. `null` for your own stock |+| `Cart.mercur_sellers` | `[MercurCartSeller!]!`: `seller`, `items`, `shipping_options`, `estimated_delivery` |+| `CartPrices.mercur_shipping` | `Money`, the seller shipping total |+| `OrderItemInterface.mercur` | `MercurOrderItem`: `seller`, `seller_order_id`, `status`, `status_label`. `null` for your own stock |+| `Query.mercurSeller(handle)` | `MercurSeller`, or `null` when the seller isn't selling |+| `Mutation.setMercurShippingMethods(input)` | Picks one shipping option per seller: `{ cart_id, shipping_methods: [{ seller_id, option_id }] }` |++`MercurOffer` has `id`, `sku`, `seller_id`, `seller_name`, `seller_premium`, `seller`, `price`, `origin_price`, `price_ranges`, `currency_code`, `quantity`, `leadtime_to_ship`, `estimated_delivery`, `condition_code`, `condition_label` and `is_best`.++## Database++### Tables++| Table | Holds |+| --- | --- |+| `mercur_seller` | The seller mirror |+| `mercur_offer` | The offer mirror, keyed by offer id, with the Magento SKU it sells |+| `mercur_offer_price` | One price per offer and website, with the strike-through price and quantity tiers |+| `mercur_offer_product_index` | The buy box per SKU and website |+| `mercur_process` | Processes, their parameters, status and output |+| `mercur_webhook_event` | Processed webhook delivery ids, for 30 days |++### Columns on Magento tables++| Table | Columns |+| --- | --- |+| `quote` | `mercur_cart_id`, `mercur_shipping_methods`, `mercur_sync_hash` |+| `quote_item` | `mercur_offer_id`, `mercur_seller_id`, `mercur_line_item_id` |+| `quote_address` | `mercur_shipping_amount`, `mercur_shipping_tax_amount`, `mercur_shipping_incl_tax` and their `base_` versions, `mercur_shipping_error` |+| `sales_order` | `mercur_cart_id`, `mercur_order_group_id`, `mercur_shipping_methods`, the seller shipping amounts, tax, invoiced and refunded with their `base_` versions, `mercur_sent_at`, `mercur_captured_at` |+| `sales_order_item` | `mercur_offer_id`, `mercur_seller_id`, `mercur_line_item_id`, `mercur_order_id`, `mercur_order_line_item_id`, `mercur_status`, `mercur_cancel_reason` |+| `sales_order_grid` | `mercur_order_group_id` |+| `sales_invoice` | The seller shipping amounts and tax |+| `sales_creditmemo` | The seller shipping amounts and tax, `mercur_refund_id`, `mercur_reported` |+| `sales_shipment` | `mercur_fulfillment_id` |++### Product attributes++In the **Marketplace** attribute group:++| Code | Label |+| --- | --- |+| `mercur_product` | Imported from Mercur |+| `mercur_product_id` | The Mercur product id |+| `mercur_variant_id` | The Mercur variant id |+| `mercur_thumbnail` | Mercur thumbnail URL |+| `mercur_scoped_attributes` | Seller attributes, as JSON |++## Magento admin++| Menu | ACL resource |+| --- | --- |+| **Mercur → Sellers** | `Mercur_Core::sellers` |+| **Mercur → Offers** | `Mercur_Core::offers` |+| **Mercur → Processes** | `Mercur_Core::process`. Running and stopping need `Mercur_Core::process_run`, deleting needs `Mercur_Core::process_delete` |+| **Mercur → Configuration** | `Mercur_Core::config` |+| Order view buttons | `Mercur_Core::orders` |++The product edit form also gets a **Marketplace offers** section listing every offer for the product's SKU.diff --git a/apps/docs/resources/integrations/magento2/storefront.mdx b/apps/docs/resources/integrations/magento2/storefront.mdxnew file mode 100644index 000000000..c4dbbfe93--- /dev/null+++ b/apps/docs/resources/integrations/magento2/storefront.mdx@@ -0,0 +1,150 @@+---+title: "Storefront"+sidebarTitle: "Storefront"+description: "What shoppers see on the product page, in the cart, at checkout, on seller pages and in their account, and how a headless storefront does the same through GraphQL and REST."+---++The connector adds marketplace behavior to Magento's own storefront: Luma and any theme built on its layouts. A headless storefront gets the same through GraphQL. Your own products look and sell exactly as before.++## Product page++Under the add-to-cart button, an **Also sold by** block lists every way to buy the product on this website:++- **Your own stock**, labelled with **Label for your own stock** ("Sold by us" by default), when you can sell it+- **Each seller offer**, cheapest first, with the seller's name linked to their page, a **Premium seller** badge, the price with a strike-through when a Mercur price list lowers it, quantity tiers ("Buy 10+ for €8.50 each"), the condition and an estimated delivery date++The way the [best offer rule](/resources/integrations/magento2/catalog-and-offers#the-buy-box) picks is marked **Best offer**. Each row has its own add-to-cart button. The main add-to-cart button buys your own stock, or the best offer when you can't sell the product.++On a configurable product, choosing options or swatches filters the block down to the selected variant's offers.++Category pages and search results show the best price for each product, or "From" the lowest price when there are several ways to buy. Products you've run out of stay listed while a seller has stock.++## Cart and checkout++Seller lines carry **Sold by** with the seller's name, on the cart, the order, the invoice and in emails. Magento's cart price rules never discount them, and a rule's subtotal or quantity conditions count your own lines only.++The cart and the shipping step of checkout group seller lines by seller. Each group shows the seller's shipping options with their price and estimated delivery, and the shopper picks one per seller. The cheapest is selected until they do. The totals show:++| Total | Contains |+| --- | --- |+| Shipping | Your own carriers, for your own lines only |+| Seller shipping | The sum of each seller's chosen option, taxed with your shipping tax class |++A cart with seller lines only offers a single method, **Shipped by the sellers**, at no extra charge.++Before totals are collected, every seller line is checked against the mirror:++| The offer… | The shopper sees |+| --- | --- |+| was withdrawn | The line is removed with a notice, or kept with an error that blocks checkout when **Remove unavailable seller lines automatically** is off |+| no longer has enough stock | `{Seller} can only ship {n} of this item.` on the line |+| changed price | The line is repriced, with `The price of {product} changed to {price}.` |++If seller shipping can't be quoted, checkout shows "Marketplace shipping could not be quoted. Please try again." and the order can't be placed until it can, from the storefront, REST or GraphQL.++## Delivery estimates++Each offer and each seller group in the cart shows `Arrives {date}` or `Arrives {from} – {to}`:++1. Start today, or the next business day when today isn't one or it's past the **Order cut-off time** in the store's timezone.+2. Add the seller's lead time in business days: the offer's, or the seller's default. In the cart, the longest lead time of the seller's lines counts.+3. Add the minimum and maximum transit days in business days: the chosen shipping option's `data.transit_days_min` and `data.transit_days_max`, or the configured defaults.++There is no holiday calendar.++## Seller pages++Every seller that is selling has a page at `/seller/{handle}`, with their banner, logo, premium badge, location, "Selling since" date, description and up to 60 of their products at their lowest price. A seller that is suspended, closed or unknown returns a 404.++## Customer account++The order view in **My Orders** adds a **Sellers** table: one row per seller with their items, shipping, status and tracking links. The status follows the seller order in Mercur:++| Status | Shown as |+| --- | --- |+| `not_fulfilled` | Processing |+| `fulfilled` | Preparing |+| `partially_shipped` | Partially shipped |+| `shipped` | Shipped |+| `delivered` | Delivered |+| `return_requested` | Return requested |+| `returned` | Returned |+| `canceled` | Canceled |+| `refused` | Refused by seller |++## GraphQL++`Mercur_GraphQl` extends Magento's schema. The full list is in the [reference](/resources/integrations/magento2/reference#graphql).++Read a product's offers and buy box:++```graphql+{+ products(filter: { sku: { eq: "MB01" } }) {+ items {+ sku+ mercur_buy_box { best_offer_id best_price offer_count operator_available }+ mercur_offers {+ id+ price+ origin_price+ price_ranges { min_quantity amount }+ seller { name handle url premium }+ estimated_delivery { from to }+ is_best+ }+ }+ }+}+```++Add a line from a seller offer by passing `mercur_offer_id` on the cart item. Without it, the line buys your own stock:++```graphql+mutation {+ addProductsToCart(+ cartId: "4JQaNVJokOpFxrykGVvYrjhiNv9qt31C"+ cartItems: [{ sku: "MB01", quantity: 1, mercur_offer_id: "offer_01J9..." }]+ ) {+ cart { items { uid mercur_offer { offer_id seller { name } } } }+ }+}+```++Read the seller groups and pick shipping per seller:++```graphql+mutation {+ setMercurShippingMethods(input: {+ cart_id: "4JQaNVJokOpFxrykGVvYrjhiNv9qt31C"+ shipping_methods: [{ seller_id: "sel_01J9...", option_id: "so_01J9..." }]+ }) {+ cart {+ mercur_sellers {+ seller { name }+ shipping_options { id name amount selected estimated_delivery { from to } }+ }+ prices { mercur_shipping { value currency } }+ }+ }+}+```++Load a seller page with `mercurSeller(handle: "...")`, and a line's seller and marketplace status with `mercur` on order items.++## REST++There are no new REST routes. To buy from a seller through the REST cart API, pass the offer id as an extension attribute of the item's product option:++```json+{+ "cartItem": {+ "quote_id": "4JQaNVJokOpFxrykGVvYrjhiNv9qt31C",+ "sku": "MB01",+ "qty": 1,+ "product_option": {+ "extension_attributes": { "mercur_offer_id": "offer_01J9..." }+ }+ }+}+```diff --git a/apps/docs/resources/integrations/overview.mdx b/apps/docs/resources/integrations/overview.mdxindex 02273e8a2..446c1d853 100644--- a/apps/docs/resources/integrations/overview.mdx+++ b/apps/docs/resources/integrations/overview.mdx@@ -28,8 +28,11 @@ interface.A storefront you already run can sell marketplace offers next to its own catalog. Mercur keeps sellers, offers, split orders, commissions and payouts; the platform keeps checkout and payment.<CardGroup cols={2}>- <Card title="Magento 2" icon="store" href="/resources/integrations/magento2">- Set up the Magento 2 connector.+ <Card title="Magento 2" icon="store" href="/resources/integrations/magento2/overview">+ Sell seller offers from your Magento 2 or Adobe Commerce store, next to your own products.+ </Card>+ <Card title="Magento 2 quickstart" icon="rocket" href="/resources/integrations/magento2/quickstart">+ Connect a store and place a first mixed order.</Card></CardGroup>