diff --git a/src/service/order.service.ts b/src/service/order.service.ts index 2b899c2..477b004 100644 --- a/src/service/order.service.ts +++ b/src/service/order.service.ts @@ -740,6 +740,7 @@ export class OrderService { const orderSales: OrderSale[] = componentDetails.map(({product, parentProduct, quantity}) => { if (!product) return null + console.log('product',product) const attrsObj = this.productService.getAttributesObject(product.attributes) const orderSale = plainToClass(OrderSale, { orderId: orderItem.orderId, @@ -758,7 +759,7 @@ export class OrderService { flavor: attrsObj?.['flavor']?.name, humidity: attrsObj?.['humidity']?.name, size: attrsObj?.['size']?.name, - category: product.category.name, + category: product.category?.name, }); return orderSale }).filter(v => v !== null) diff --git a/src/service/product.service.ts b/src/service/product.service.ts index 9984dcf..c81959b 100644 --- a/src/service/product.service.ts +++ b/src/service/product.service.ts @@ -1786,7 +1786,7 @@ export class ProductService { } } // 获取库存单品列表 - async getComponentDetailFromSiteSku(siteProduct: { sku: string, name: string }, site: Site): Promise<{ product: Product,parentProduct?: Product, quantity: number }[]> { + async getComponentDetailFromSiteSku(siteProduct: { sku: string, name?: string }, site: Site): Promise<{ product: Product,parentProduct?: Product, quantity: number }[]> { if (!siteProduct.sku) { throw new Error('siteSku 不能为空') } @@ -1805,7 +1805,8 @@ export class ProductService { return await Promise.all(product.components.map(async comp => { return { product: await this.productModel.findOne({ - where: { id: comp.productId }, + where: { sku: comp.sku }, + relations: ['category', 'attributes', 'attributes.dict', 'components'] }), parentProduct: product, // 这里得记录一下他的爸爸用来记录 quantity: comp.quantity, @@ -2133,11 +2134,6 @@ export class ProductService { component.sku = product.sku; component.quantity = 1; product.components = [component]; - } else { - // 混装商品返回持久化的 SKU 组成 - product.components = await this.productStockComponentModel.find({ - where: { productId: product.id }, - }); } return product;