fix(commerce-backend): traer name/title explicito en el importador
listProductCategories({})/listProductCollections({}) sin select
explicito devolvian name/title undefined (a diferencia de la capa HTTP
del Admin API, que si los trae completos por defecto) -- causaba un 500
"Cannot read properties of undefined (reading 'toLowerCase')" en
cualquier import real. Confirmado en vivo con una prueba de importacion
de 3 productos antes de este fix.
De paso, se agrega un filtro defensivo antes del .map() para que una
categoria/coleccion sin nombre no tumbe el import entero.
This commit is contained in:
1 parent
8126bb3d81
commit
2b0d50c3d0
1 file changed
+13
-4
@@ -116,8 +116,13 @@ export async function POST(req: MedusaRequest<{ csv: string }>, res: MedusaRespo
|
||||
stockLocationService.listStockLocations({}),
|
||||
fulfillmentService.listShippingProfiles({}),
|
||||
salesChannelService.listSalesChannels({}),
|
||||
productService.listProductCategories({}),
|
||||
productService.listProductCollections({}),
|
||||
// select explicito -- sin el, name/title llegaban undefined (el
|
||||
// default de estos module services no siempre trae todos los
|
||||
// escalares, a diferencia de la capa HTTP del Admin API, confirmado
|
||||
// en vivo: la ruta /admin/product-categories con fields=id,name si
|
||||
// los trae completos).
|
||||
productService.listProductCategories({}, { select: ["id", "name"] }),
|
||||
productService.listProductCollections({}, { select: ["id", "title"] }),
|
||||
]);
|
||||
|
||||
const locationId = locations[0]?.id;
|
||||
@@ -131,8 +136,12 @@ export async function POST(req: MedusaRequest<{ csv: string }>, res: MedusaRespo
|
||||
return;
|
||||
}
|
||||
|
||||
const categoryByName = new Map(categories.map((c) => [c.name.toLowerCase().trim(), c.id]));
|
||||
const collectionByName = new Map(collections.map((c) => [c.title.toLowerCase().trim(), c.id]));
|
||||
const categoryByName = new Map(
|
||||
categories.filter((c) => c.name).map((c) => [c.name.toLowerCase().trim(), c.id]),
|
||||
);
|
||||
const collectionByName = new Map(
|
||||
collections.filter((c) => c.title).map((c) => [c.title.toLowerCase().trim(), c.id]),
|
||||
);
|
||||
|
||||
const results: RowResult[] = [];
|
||||
|
||||
|
||||
Reference in new issue
Block a user