fix: 修复订单服务中产品属性和组件处理的问题
处理产品属性为空的情况,避免空指针异常 为产品组件查询添加关联关系 在订单销售记录创建时增加对空产品的过滤 添加新的品牌判断逻辑
This commit is contained in:
parent
78d82ffbac
commit
8d0eec06fd
|
|
@ -449,7 +449,7 @@ export class OrderService {
|
|||
* @returns 保存后的订单实体
|
||||
*/
|
||||
// 这里 omit 是因为处理在外头了 其实 saveOrder 应该包括 savelineitems 等
|
||||
async saveOrder(siteId: number, order: Omit<UnifiedOrderDTO, 'line_items'|'refunds'>): Promise<Order> {
|
||||
async saveOrder(siteId: number, order: Omit<UnifiedOrderDTO, 'line_items' | 'refunds'>): Promise<Order> {
|
||||
// 将外部订单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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue