refactor(shopyy): 统一账单地址字段名并添加空值检查

将 billing_address 字段重命名为 bill_address 以保持命名一致性
在订单映射方法中添加空值检查防止空对象错误
This commit is contained in:
tikkhun 2026-01-10 15:48:39 +08:00
parent 5d7e0090aa
commit ca0b5e63a7
2 changed files with 6 additions and 4 deletions

View File

@ -227,8 +227,10 @@ export class ShopyyAdapter implements ISiteAdapter {
// ========== 订单映射方法 ========== // ========== 订单映射方法 ==========
mapPlatformToUnifiedOrder(item: ShopyyOrder): UnifiedOrderDTO { mapPlatformToUnifiedOrder(item: ShopyyOrder): UnifiedOrderDTO {
console.log(item)
if(!item) throw new Error('订单数据不能为空')
// 提取账单和送货地址 如果不存在则为空对象 // 提取账单和送货地址 如果不存在则为空对象
const billing = (item as any).billing_address || {}; const billing = (item).bill_address || {};
const shipping = (item as any).shipping_address || {}; const shipping = (item as any).shipping_address || {};
// 构建账单地址对象 // 构建账单地址对象
@ -237,7 +239,7 @@ export class ShopyyAdapter implements ISiteAdapter {
last_name: billing.last_name || item.lastname || '', last_name: billing.last_name || item.lastname || '',
fullname: billing.name || `${item.firstname} ${item.lastname}`.trim(), fullname: billing.name || `${item.firstname} ${item.lastname}`.trim(),
company: billing.company || '', company: billing.company || '',
email: item.customer_email || item.email || '', email: item.customer_email || item.email || '',
phone: billing.phone || (item as any).telephone || '', phone: billing.phone || (item as any).telephone || '',
address_1: billing.address1 || item.payment_address || '', address_1: billing.address1 || item.payment_address || '',
address_2: billing.address2 || '', address_2: billing.address2 || '',
@ -440,7 +442,7 @@ export class ShopyyAdapter implements ISiteAdapter {
} }
// 更新账单地址 // 更新账单地址
params.billing_address = params.billing_address || {}; params.billing_address = params?.billing_address || {};
if (data.billing.first_name !== undefined) { if (data.billing.first_name !== undefined) {
params.billing_address.first_name = data.billing.first_name; params.billing_address.first_name = data.billing.first_name;
} }

View File

@ -200,7 +200,7 @@ export interface ShopyyOrder {
customer_email?: string; customer_email?: string;
email?: string; email?: string;
// 地址字段 // 地址字段
billing_address?: { bill_address?: {
first_name?: string; first_name?: string;
last_name?: string; last_name?: string;
name?: string; name?: string;