diff --git a/src/service/order.service.ts b/src/service/order.service.ts index 999c86d..f0aaca7 100644 --- a/src/service/order.service.ts +++ b/src/service/order.service.ts @@ -449,7 +449,7 @@ export class OrderService { * @returns 保存后的订单实体 */ // 这里 omit 是因为处理在外头了 其实 saveOrder 应该包括 savelineitems 等 - async saveOrder(siteId: number, order: Omit): Promise { + async saveOrder(siteId: number, order: Omit): Promise { // 将外部订单ID转换为字符串 const externalOrderId = String(order.id) delete order.id @@ -722,12 +722,14 @@ export class OrderService { return { product: await this.productModel.findOne({ where: { sku: comp.sku }, + relations: ['components','attributes'], }), quantity: comp.quantity * orderItem.quantity, } - })) : [{ product, quantity: orderItem.quantity }]; + })) : [{ product, quantity: orderItem.quantity }] const orderSales: OrderSale[] = componentDetails.map(componentDetail => { + if(!componentDetail.product) return null const attrsObj = this.productService.getAttributesObject(product.attributes) const orderSale = plainToClass(OrderSale, { orderId: orderItem.orderId, @@ -740,11 +742,12 @@ export class OrderService { isPackage: componentDetail.product.type === 'bundle', isYoone: attrsObj?.['brand']?.name === 'yoone', isZyn: attrsObj?.['brand']?.name === 'zyn', + isZex: attrsObj?.['brand']?.name === 'zex', isYooneNew: attrsObj?.['brand']?.name === 'yoone' && attrsObj?.['version']?.name === 'new', size: this.extractNumberFromString(attrsObj?.['strength']?.name) || null, }); return orderSale - }) + }).filter(v => v !== null) if (orderSales.length > 0) { await this.orderSaleModel.save(orderSales); diff --git a/src/service/product.service.ts b/src/service/product.service.ts index b641571..78ffeb9 100644 --- a/src/service/product.service.ts +++ b/src/service/product.service.ts @@ -1537,6 +1537,7 @@ export class ProductService { return dto; } getAttributesObject(attributes:DictItem[]){ + if(!attributes) return {} const obj:any = {} attributes.forEach(attr=>{ obj[attr.dict.name] = attr