forked from yoone/API
fix(订单服务): 修复产品分类可能为空的错误并优化产品查询
修复订单服务中产品分类可能为空导致的错误,改为可选链操作 优化产品服务中组件查询逻辑,使用sku查询并添加关联关系 移除产品服务中不必要的组件查询逻辑
This commit is contained in:
parent
f37de5ac32
commit
0b211628f3
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue