fix(product): updating collections with products fix (#10668)
This commit is contained in:
+2
-1
@@ -7,11 +7,11 @@ import {
|
||||
ProductStatus,
|
||||
toMikroORMEntity,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { Product, ProductCollection } from "@models"
|
||||
import {
|
||||
MockEventBusService,
|
||||
moduleIntegrationTestRunner,
|
||||
} from "@medusajs/test-utils"
|
||||
import { Product, ProductCollection } from "@models"
|
||||
import { createCollections } from "../../__fixtures__/product"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
@@ -318,6 +318,7 @@ moduleIntegrationTestRunner<IProductModuleService>({
|
||||
{
|
||||
id: collectionId,
|
||||
title: "New Collection",
|
||||
product_ids: ["product_id"],
|
||||
},
|
||||
])
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user