feat: V2 batch update products in categories (#7125)
* wip * wip * fix: batch category update * update tet * fix type --------- Co-authored-by: Stevche Radevski <sradevski@live.com>
This commit is contained in:
1 parent
2446151420
commit
10e120062b
13 files changed
+269
-25
No files matched your search
+5
-1
@@ -1,7 +1,11 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { IProductModuleService, ProductTypes } from "@medusajs/types"
|
||||
import { Product, ProductCategory } from "@models"
|
||||
import { MockEventBusService, SuiteOptions, moduleIntegrationTestRunner } from "medusa-test-utils"
|
||||
import {
|
||||
MockEventBusService,
|
||||
SuiteOptions,
|
||||
moduleIntegrationTestRunner,
|
||||
} from "medusa-test-utils"
|
||||
import { createProductCategories } from "../../../__fixtures__/product-category"
|
||||
import { productCategoriesRankData } from "../../../__fixtures__/product-category/data"
|
||||
|
||||
|
||||
@@ -127,12 +127,15 @@ export default class ProductModuleService<
|
||||
|
||||
// eslint-disable-next-line max-len
|
||||
protected readonly productCategoryService_: ProductCategoryService<TProductCategory>
|
||||
// eslint-disable-next-line max-len
|
||||
protected readonly productTagService_: ModulesSdkTypes.InternalModuleService<TProductTag>
|
||||
// eslint-disable-next-line max-len
|
||||
protected readonly productCollectionService_: ModulesSdkTypes.InternalModuleService<TProductCollection>
|
||||
// eslint-disable-next-line max-len
|
||||
protected readonly productImageService_: ModulesSdkTypes.InternalModuleService<TProductImage>
|
||||
// eslint-disable-next-line max-len
|
||||
protected readonly productTypeService_: ModulesSdkTypes.InternalModuleService<TProductType>
|
||||
// eslint-disable-next-line max-len
|
||||
protected readonly productOptionService_: ModulesSdkTypes.InternalModuleService<TProductOption>
|
||||
// eslint-disable-next-line max-len
|
||||
protected readonly productOptionValueService_: ModulesSdkTypes.InternalModuleService<TProductOptionValue>
|
||||
@@ -1369,6 +1372,15 @@ export default class ProductModuleService<
|
||||
})
|
||||
}
|
||||
|
||||
if (productData.category_ids) {
|
||||
;(productData as any).categories = productData.category_ids.map(
|
||||
(cid) => ({
|
||||
id: cid,
|
||||
})
|
||||
)
|
||||
delete productData.category_ids
|
||||
}
|
||||
|
||||
return productData
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
FindConfig,
|
||||
ProductTypes,
|
||||
BaseFilterable,
|
||||
FilterableProductProps,
|
||||
} from "@medusajs/types"
|
||||
import { InjectManager, MedusaContext, ModulesSdkUtils } from "@medusajs/utils"
|
||||
import { Product } from "@models"
|
||||
@@ -60,21 +61,22 @@ export default class ProductService<
|
||||
}
|
||||
|
||||
protected static normalizeFilters(
|
||||
filters: NormalizedFilterableProductProps = {}
|
||||
filters: FilterableProductProps = {}
|
||||
): NormalizedFilterableProductProps {
|
||||
if (filters.category_id) {
|
||||
if (Array.isArray(filters.category_id)) {
|
||||
filters.categories = {
|
||||
id: { $in: filters.category_id },
|
||||
const normalized = filters as NormalizedFilterableProductProps
|
||||
if (normalized.category_id) {
|
||||
if (Array.isArray(normalized.category_id)) {
|
||||
normalized.categories = {
|
||||
id: { $in: normalized.category_id },
|
||||
}
|
||||
} else {
|
||||
filters.categories = {
|
||||
id: filters.category_id as string,
|
||||
normalized.categories = {
|
||||
id: normalized.category_id as string,
|
||||
}
|
||||
}
|
||||
delete filters.category_id
|
||||
delete normalized.category_id
|
||||
}
|
||||
|
||||
return filters
|
||||
return normalized
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user