forked from yoone/API
feat(woocommerce): 添加物流追踪创建和更新接口
添加 WooFulfillmentCreateParams 接口定义并重构物流追踪创建和更新方法 使用统一的 FulfillmentDTO 类型简化参数处理
This commit is contained in:
parent
cb876e8c0f
commit
d5384944a4
|
|
@ -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<any> {
|
||||
const shipmentData: any = {
|
||||
shipping_provider: data.shipping_provider,
|
||||
async createOrderFulfillment(orderId: string | number, data: FulfillmentDTO): Promise<any> {
|
||||
const shipmentData: Partial<WooFulfillment> = {
|
||||
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<any> {
|
||||
return await this.wpService.updateFulfillment(this.site, String(orderId), fulfillmentId, data);
|
||||
async updateOrderFulfillment(orderId: string | number, fulfillmentId: string, data: FulfillmentDTO): Promise<any> {
|
||||
const shipmentData: Partial<WooFulfillment> = {
|
||||
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<boolean> {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue