This commit is contained in:
adrien2p
2024-05-06 13:52:30 +02:00
parent 7b2879d643
commit 36eff7f10a
2 changed files with 5 additions and 6 deletions

View File

@@ -2,7 +2,7 @@ import { ProductCategoryService } from "@services"
import { Modules } from "@medusajs/modules-sdk" import { Modules } from "@medusajs/modules-sdk"
import { IProductModuleService } from "@medusajs/types" import { IProductModuleService } from "@medusajs/types"
import { SuiteOptions, moduleIntegrationTestRunner } from "medusa-test-utils" import { moduleIntegrationTestRunner, SuiteOptions } from "medusa-test-utils"
import { createProductCategories } from "../../../__fixtures__/product-category" import { createProductCategories } from "../../../__fixtures__/product-category"
import { import {
eletronicsCategoriesData, eletronicsCategoriesData,
@@ -199,13 +199,13 @@ moduleIntegrationTestRunner({
mpath: "category-0.category-1.category-1-b.", mpath: "category-0.category-1.category-1-b.",
parent_category_id: "category-1", parent_category_id: "category-1",
category_children: [ category_children: [
{ expect.objectContaining({
id: "category-1-b-1", id: "category-1-b-1",
handle: "category-1-b-1", handle: "category-1-b-1",
mpath: "category-0.category-1.category-1-b.category-1-b-1.", mpath: "category-0.category-1.category-1-b.category-1-b-1.",
parent_category_id: "category-1-b", parent_category_id: "category-1-b",
category_children: [], category_children: [],
}, }),
], ],
}, },
]) ])

View File

@@ -51,7 +51,7 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito
} }
const shouldExpandParent = const shouldExpandParent =
familyOptions.includeAncestorsTree || fields.includes("parent_category") familyOptions.includeAncestorsTree || populate.includes("parent_category") || fields.some(field => field.startsWith('parent_category'))
if (shouldExpandParent) { if (shouldExpandParent) {
populate.indexOf("parent_category") === -1 && populate.indexOf("parent_category") === -1 &&
@@ -59,8 +59,7 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito
} }
const shouldExpandChildren = const shouldExpandChildren =
familyOptions.includeDescendantsTree || familyOptions.includeDescendantsTree || populate.includes("category_children") || fields.some(field => field.startsWith('category_children'))
fields.includes("category_children")
if (shouldExpandChildren) { if (shouldExpandChildren) {
populate.indexOf("category_children") === -1 && populate.indexOf("category_children") === -1 &&