CJ Fulfillment Engine
Automates the WooCommerce → CJ Dropshipping order flow. No manual copy-paste.
What it does
- 1. Fetches all
processing orders from WooCommerce - Maps line items to CJ variant IDs via INLINECODE1
- Submits matched items to CJ API as a dropship order
- Updates WooCommerce order status to
on-hold (awaiting CJ dispatch) - Adds an order note with the CJ order ID
- Logs all results to INLINECODE3
Credentials / paths
| File | Contents |
|---|
| INLINECODE4 | INLINECODE5 |
| INLINECODE6 |
{ apiKey, baseUrl, accessToken, tokenExpiry } |
|
cj-supplier-selection.json | Array of
{ sku, cjProductId, variantId, ... } |
Usage
CODEBLOCK0
cj-supplier-selection.json format
Full 6-field schema — one entry per product variant. Matching is SKU-first with fallback to wooProductId:wooVariationId.
CODEBLOCK1
Generate or rebuild this file from CJ API automatically:
CODEBLOCK2
FBA / excluded products
Products that should never be fulfilled via CJ (e.g. FBA, in-house). Set via env var:
CODEBLOCK3
These are skipped with a log entry: "FBA product — manual fulfillment required".
Output
- - Console: per-order summary with matched/unmatched items and CJ order ID
- INLINECODE12 : append-only log with INLINECODE13
- INLINECODE14 : unmatched/skipped items for manual review
Unmatched items
If a line item has no SKU match and no wooProductId:wooVariationId match, it's logged to the rejection log and the order is skipped. Fix by running rebuild-mapping.js or adding the entry manually.
Environment overrides
CODEBLOCK4
CJ 订单履行引擎
自动化 WooCommerce → CJ 一件代发订单流程。无需手动复制粘贴。
功能说明
- 1. 从 WooCommerce 获取所有 processing 状态的订单
- 通过 cj-supplier-selection.json 将订单行项目映射到 CJ 变体 ID
- 将匹配的商品作为一件代发订单提交至 CJ API
- 将 WooCommerce 订单状态更新为 on-hold(等待 CJ 发货)
- 添加包含 CJ 订单 ID 的订单备注
- 将所有结果记录到 cj-fulfillment-log.json
凭据/路径
| 文件 | 内容 |
|---|
| woo-api.json | { url, consumerKey, consumerSecret } |
| cj-api.json |
{ apiKey, baseUrl, accessToken, tokenExpiry } |
| cj-supplier-selection.json | { sku, cjProductId, variantId, ... } 数组 |
使用方法
bash
试运行 — 预览但不实际下单
node {baseDir}/scripts/fulfill.js --dry-run
履行所有 processing 状态的订单
node {baseDir}/scripts/fulfill.js
履行单个 WooCommerce 订单
node {baseDir}/scripts/fulfill.js --order 1234
cj-supplier-selection.json 格式
完整的 6 字段架构 — 每个产品变体一条记录。匹配规则优先使用 SKU,其次回退到 wooProductId:wooVariationId。
json
[
{
wooProductId: 77261,
wooVariationId: 77265,
sku: CJYD2360896-BLACK,
cjProductId: CJ-PRODUCT-ID,
variantId: CJ-VARIANT-ID,
productName: 我的产品 — 黑色
}
]
通过 CJ API 自动生成或重建此文件:
bash
node {baseDir}/scripts/rebuild-mapping.js
FBA / 排除产品
不应通过 CJ 履行的产品(例如 FBA、自营产品)。通过环境变量设置:
bash
FBAPRODUCTIDS=75927,75808,2382 node fulfill.js
这些产品将被跳过并记录日志:FBA 产品 — 需要手动履行。
输出
- - 控制台:每个订单的摘要,包含匹配/未匹配的商品和 CJ 订单 ID
- cj-fulfillment-log.json:仅追加的日志,包含 { orderId, status, cjOrderId, timestamp }
- cj-rejection-log.json:未匹配/跳过的商品,供人工审核
未匹配商品
如果某个订单行项目既没有 SKU 匹配,也没有 wooProductId:wooVariationId 匹配,则记录到拒绝日志中,并跳过该订单。通过运行 rebuild-mapping.js 或手动添加条目来修复。
环境变量覆盖
bash
CJSELECTIONPATH=/custom/path/selection.json node fulfill.js
FULFILLLOGPATH=/custom/path/log.json node fulfill.js