From 87fa07bab78e121196d92310a323471adfcf0a65 Mon Sep 17 00:00:00 2001 From: fPolic Date: Fri, 15 Dec 2023 11:03:06 +0100 Subject: [PATCH] fix: add sc to filter to list --- .../utils/queries/products/list-products.ts | 47 +++++++------------ 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/packages/medusa/src/utils/queries/products/list-products.ts b/packages/medusa/src/utils/queries/products/list-products.ts index 5bc2402b1bc49..117fe0dde4611 100644 --- a/packages/medusa/src/utils/queries/products/list-products.ts +++ b/packages/medusa/src/utils/queries/products/list-products.ts @@ -1,7 +1,7 @@ import { MedusaContainer } from "@medusajs/types" import { MedusaV2Flag, promiseAll } from "@medusajs/utils" -import { PriceListService, SalesChannelService } from "../../../services" +import { PriceListService } from "../../../services" import { getVariantsFromPriceList } from "./get-variants-from-price-list" export async function listProducts( @@ -23,35 +23,6 @@ export async function listProducts( const salesChannelIdFilter = filterableFields.sales_channel_id delete filterableFields.sales_channel_id - if (salesChannelIdFilter) { - const salesChannelService = container.resolve( - "salesChannelService" - ) as SalesChannelService - - promises.push( - salesChannelService - .listProductIdsBySalesChannelIds(salesChannelIdFilter) - .then((productIdsInSalesChannel) => { - let filteredProductIds = - productIdsInSalesChannel[salesChannelIdFilter] - - if (filterableFields.id) { - filterableFields.id = Array.isArray(filterableFields.id) - ? filterableFields.id - : [filterableFields.id] - - const salesChannelProductIdsSet = new Set(filteredProductIds) - - filteredProductIds = filterableFields.id.filter((productId) => - salesChannelProductIdsSet.has(productId) - ) - } - - filteredProductIds.map((id) => productIdsFilter.add(id)) - }) - ) - } - const priceListId = filterableFields.price_list_id delete filterableFields.price_list_id @@ -112,6 +83,10 @@ export async function listProducts( }, } + if (salesChannelIdFilter) { + query.product["sales_channels"]["__args"] = { id: salesChannelIdFilter } + } + const { rows: products, metadata: { count }, @@ -245,4 +220,16 @@ export const defaultAdminProductRemoteQueryObject = { profile: { fields: ["id", "created_at", "updated_at", "deleted_at", "name", "type"], }, + sales_channels: { + fields: [ + "id", + "name", + "description", + "is_disabled", + "created_at", + "updated_at", + "deleted_at", + "metadata", + ], + }, }