fix(product): updating collections with products fix (#10668)

This commit is contained in:
Riqwan Thamir
2024-12-19 16:31:45 +01:00
committed by GitHub
parent 5d1098ceb9
commit d08b71f9b8
4 changed files with 69 additions and 10 deletions
@@ -27,6 +27,7 @@ import {
EmitEvents,
InjectManager,
InjectTransactionManager,
isDefined,
isPresent,
isString,
isValidHandle,
@@ -1056,6 +1057,7 @@ export default class ProductModuleService
if (forCreate.length) {
created = await this.createCollections_(forCreate, sharedContext)
}
if (forUpdate.length) {
updated = await this.updateCollections_(forUpdate, sharedContext)
}
@@ -1173,8 +1175,11 @@ export default class ProductModuleService
if (!!productsToUpdate?.length) {
const productIds = productsToUpdate.map((p) => p.id)
dissociateSelector["id"] = { $nin: productIds }
associateSelector["id"] = { $in: productIds }
} else if (!isDefined(productsToUpdate)) {
return []
}
const result: Record<string, any>[] = [
@@ -1204,7 +1209,10 @@ export default class ProductModuleService
}
)
await this.productService_.update(updateSelectorAndData, sharedContext)
if (updateSelectorAndData.length) {
await this.productService_.update(updateSelectorAndData, sharedContext)
}
return collections
}
@@ -1888,12 +1896,11 @@ export default class ProductModuleService
collection: ProductTypes.CreateProductCollectionDTO | UpdateCollectionInput
): ProductTypes.CreateProductCollectionDTO | UpdateCollectionInput {
const collectionData = { ...collection }
if (collectionData.product_ids?.length) {
if (Array.isArray(collectionData.product_ids)) {
;(collectionData as any).products = collectionData.product_ids.map(
(pid) => ({
id: pid,
})
(pid) => ({ id: pid })
)
delete collectionData.product_ids
}