From d5384944a453a1b9ae6b6a09bc09855098ef852e Mon Sep 17 00:00:00 2001 From: tikkhun Date: Thu, 22 Jan 2026 14:44:42 +0800 Subject: [PATCH] =?UTF-8?q?feat(woocommerce):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=89=A9=E6=B5=81=E8=BF=BD=E8=B8=AA=E5=88=9B=E5=BB=BA=E5=92=8C?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加 WooFulfillmentCreateParams 接口定义并重构物流追踪创建和更新方法 使用统一的 FulfillmentDTO 类型简化参数处理 --- src/adapter/woocommerce.adapter.ts | 58 +++++++++--------------------- src/dto/woocommerce.dto.ts | 9 +++++ 2 files changed, 25 insertions(+), 42 deletions(-) diff --git a/src/adapter/woocommerce.adapter.ts b/src/adapter/woocommerce.adapter.ts index 9fe5549..0246569 100644 --- a/src/adapter/woocommerce.adapter.ts +++ b/src/adapter/woocommerce.adapter.ts @@ -17,6 +17,7 @@ import { UnifiedVariationPaginationDTO, CreateReviewDTO, UpdateReviewDTO, + FulfillmentDTO, } from '../dto/site-api.dto'; import { UnifiedPaginationDTO, UnifiedSearchParamsDTO } from '../dto/api.dto'; import { @@ -29,6 +30,7 @@ import { WooOrderSearchParams, WooProductSearchParams, WpMediaGetListParams, + WooFulfillment, } from '../dto/woocommerce.dto'; import { Site } from '../entity/site.entity'; import { WPService } from '../service/wp.service'; @@ -357,6 +359,7 @@ export class WooCommerceAdapter implements ISiteAdapter { // 集合过滤参数 if (where.exclude) mapped.exclude = toArray(where.exclude); if (where.include) mapped.include = toArray(where.include); + if (where.ids) mapped.include = toArray(where.ids); if (toNumber(where.offset) !== undefined) mapped.offset = Number(where.offset); if (where.parent ?? where.parentId) mapped.parent = toArray(where.parent ?? where.parentId); @@ -539,54 +542,25 @@ export class WooCommerceAdapter implements ISiteAdapter { return await this.wpService.getFulfillments(this.site, String(orderId)); } - async createOrderFulfillment(orderId: string | number, data: { - tracking_number: string; - shipping_provider: string; - shipping_method?: string; - status?: string; - date_created?: string; - items?: Array<{ - order_item_id: number; - quantity: number; - }>; - }): Promise { - const shipmentData: any = { - shipping_provider: data.shipping_provider, + async createOrderFulfillment(orderId: string | number, data: FulfillmentDTO): Promise { + const shipmentData: Partial = { + tracking_provider: data.shipping_provider, tracking_number: data.tracking_number, - }; - - if (data.shipping_method) { - shipmentData.shipping_method = data.shipping_method; + data_sipped: data.date_created, + // items: data.items, } - - if (data.status) { - shipmentData.status = data.status; - } - - if (data.date_created) { - shipmentData.date_created = data.date_created; - } - - if (data.items) { - shipmentData.items = data.items; - } - const response = await this.wpService.createFulfillment(this.site, String(orderId), shipmentData); return response.data; } - async updateOrderFulfillment(orderId: string | number, fulfillmentId: string, data: { - tracking_number?: string; - shipping_provider?: string; - shipping_method?: string; - status?: string; - date_created?: string; - items?: Array<{ - order_item_id: number; - quantity: number; - }>; - }): Promise { - return await this.wpService.updateFulfillment(this.site, String(orderId), fulfillmentId, data); + async updateOrderFulfillment(orderId: string | number, fulfillmentId: string, data: FulfillmentDTO): Promise { + const shipmentData: Partial = { + tracking_provider: data.shipping_provider, + tracking_number: data.tracking_number, + data_sipped: data.date_created, + // items: data.items, + } + return await this.wpService.updateFulfillment(this.site, String(orderId), fulfillmentId, shipmentData); } async deleteOrderFulfillment(orderId: string | number, fulfillmentId: string): Promise { diff --git a/src/dto/woocommerce.dto.ts b/src/dto/woocommerce.dto.ts index 1490dba..29245b7 100644 --- a/src/dto/woocommerce.dto.ts +++ b/src/dto/woocommerce.dto.ts @@ -373,6 +373,7 @@ export interface WooOrder { fulfillments?: WooFulfillment[]; } // 这个是一个插件的物流追踪信息 +// 接口: export interface WooFulfillment { data_sipped: string; tracking_id: string; @@ -380,6 +381,14 @@ export interface WooFulfillment { tracking_number: string; tracking_provider: string; } +// https://docs.zorem.com/docs/ast-free/developers/adding-tracking-info-to-orders/ +export interface WooFulfillmentCreateParams { + order_id: string; + tracking_provider: string; + tracking_number: string; + date_shipped?: string; + status_shipped?: string; +} export interface WooOrderRefund { id?: number; reason?: string;