forked from yoone/API
feat(woocommerce): 添加物流追踪创建和更新接口
添加 WooFulfillmentCreateParams 接口定义并重构物流追踪创建和更新方法 使用统一的 FulfillmentDTO 类型简化参数处理
This commit is contained in:
parent
cb876e8c0f
commit
d5384944a4
|
|
@ -17,6 +17,7 @@ import {
|
||||||
UnifiedVariationPaginationDTO,
|
UnifiedVariationPaginationDTO,
|
||||||
CreateReviewDTO,
|
CreateReviewDTO,
|
||||||
UpdateReviewDTO,
|
UpdateReviewDTO,
|
||||||
|
FulfillmentDTO,
|
||||||
} from '../dto/site-api.dto';
|
} from '../dto/site-api.dto';
|
||||||
import { UnifiedPaginationDTO, UnifiedSearchParamsDTO } from '../dto/api.dto';
|
import { UnifiedPaginationDTO, UnifiedSearchParamsDTO } from '../dto/api.dto';
|
||||||
import {
|
import {
|
||||||
|
|
@ -29,6 +30,7 @@ import {
|
||||||
WooOrderSearchParams,
|
WooOrderSearchParams,
|
||||||
WooProductSearchParams,
|
WooProductSearchParams,
|
||||||
WpMediaGetListParams,
|
WpMediaGetListParams,
|
||||||
|
WooFulfillment,
|
||||||
} from '../dto/woocommerce.dto';
|
} from '../dto/woocommerce.dto';
|
||||||
import { Site } from '../entity/site.entity';
|
import { Site } from '../entity/site.entity';
|
||||||
import { WPService } from '../service/wp.service';
|
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.exclude) mapped.exclude = toArray(where.exclude);
|
||||||
if (where.include) mapped.include = toArray(where.include);
|
if (where.include) mapped.include = toArray(where.include);
|
||||||
|
|
||||||
if (where.ids) mapped.include = toArray(where.ids);
|
if (where.ids) mapped.include = toArray(where.ids);
|
||||||
if (toNumber(where.offset) !== undefined) mapped.offset = Number(where.offset);
|
if (toNumber(where.offset) !== undefined) mapped.offset = Number(where.offset);
|
||||||
if (where.parent ?? where.parentId) mapped.parent = toArray(where.parent ?? where.parentId);
|
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));
|
return await this.wpService.getFulfillments(this.site, String(orderId));
|
||||||
}
|
}
|
||||||
|
|
||||||
async createOrderFulfillment(orderId: string | number, data: {
|
async createOrderFulfillment(orderId: string | number, data: FulfillmentDTO): Promise<any> {
|
||||||
tracking_number: string;
|
const shipmentData: Partial<WooFulfillment> = {
|
||||||
shipping_provider: string;
|
tracking_provider: data.shipping_provider,
|
||||||
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,
|
|
||||||
tracking_number: data.tracking_number,
|
tracking_number: data.tracking_number,
|
||||||
};
|
data_sipped: data.date_created,
|
||||||
|
// items: data.items,
|
||||||
if (data.shipping_method) {
|
|
||||||
shipmentData.shipping_method = data.shipping_method;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
const response = await this.wpService.createFulfillment(this.site, String(orderId), shipmentData);
|
||||||
return response.data;
|
return response.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateOrderFulfillment(orderId: string | number, fulfillmentId: string, data: {
|
async updateOrderFulfillment(orderId: string | number, fulfillmentId: string, data: FulfillmentDTO): Promise<any> {
|
||||||
tracking_number?: string;
|
const shipmentData: Partial<WooFulfillment> = {
|
||||||
shipping_provider?: string;
|
tracking_provider: data.shipping_provider,
|
||||||
shipping_method?: string;
|
tracking_number: data.tracking_number,
|
||||||
status?: string;
|
data_sipped: data.date_created,
|
||||||
date_created?: string;
|
// items: data.items,
|
||||||
items?: Array<{
|
}
|
||||||
order_item_id: number;
|
return await this.wpService.updateFulfillment(this.site, String(orderId), fulfillmentId, shipmentData);
|
||||||
quantity: number;
|
|
||||||
}>;
|
|
||||||
}): Promise<any> {
|
|
||||||
return await this.wpService.updateFulfillment(this.site, String(orderId), fulfillmentId, data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteOrderFulfillment(orderId: string | number, fulfillmentId: string): Promise<boolean> {
|
async deleteOrderFulfillment(orderId: string | number, fulfillmentId: string): Promise<boolean> {
|
||||||
|
|
|
||||||
|
|
@ -373,6 +373,7 @@ export interface WooOrder {
|
||||||
fulfillments?: WooFulfillment[];
|
fulfillments?: WooFulfillment[];
|
||||||
}
|
}
|
||||||
// 这个是一个插件的物流追踪信息
|
// 这个是一个插件的物流追踪信息
|
||||||
|
// 接口:
|
||||||
export interface WooFulfillment {
|
export interface WooFulfillment {
|
||||||
data_sipped: string;
|
data_sipped: string;
|
||||||
tracking_id: string;
|
tracking_id: string;
|
||||||
|
|
@ -380,6 +381,14 @@ export interface WooFulfillment {
|
||||||
tracking_number: string;
|
tracking_number: string;
|
||||||
tracking_provider: 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 {
|
export interface WooOrderRefund {
|
||||||
id?: number;
|
id?: number;
|
||||||
reason?: string;
|
reason?: string;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue