From 8af4fb0ba7fe85f3def7745aa762d9ba66d5b476 Mon Sep 17 00:00:00 2001 From: Riqwan Thamir <rmthamir@gmail.com> Date: Tue, 28 Jan 2025 11:26:29 +0100 Subject: [PATCH] feat(medusa): add sku to variant query params (#11151) what: - adds sku to variant query params --- packages/core/types/src/product/common.ts | 6 +++++- packages/medusa/src/api/store/products/validators.ts | 11 ++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/core/types/src/product/common.ts b/packages/core/types/src/product/common.ts index 4fc9bc8c99789..3969fc5d1a7d4 100644 --- a/packages/core/types/src/product/common.ts +++ b/packages/core/types/src/product/common.ts @@ -697,6 +697,10 @@ export interface FilterableProductProps * The handles to filter products by. */ handle?: string | string[] + /** + * The skus to filter products by. + */ + sku?: string | string[] /** * The IDs to filter products by. */ @@ -1239,7 +1243,7 @@ export interface UpdateProductOptionValueDTO { /** * @interface - * + * * Inventory kit for creating a product variant. */ export interface CreateProductVariantInventoryKit { diff --git a/packages/medusa/src/api/store/products/validators.ts b/packages/medusa/src/api/store/products/validators.ts index 74cd966450ff8..8f3fd9c7cf8cc 100644 --- a/packages/medusa/src/api/store/products/validators.ts +++ b/packages/medusa/src/api/store/products/validators.ts @@ -28,7 +28,10 @@ export const StoreGetProductParams = createSelectParams().merge( export const StoreGetProductVariantsParamsFields = z.object({ q: z.string().optional(), id: z.union([z.string(), z.array(z.string())]).optional(), - options: z.object({ value: z.string().optional(), option_id: z.string().optional() }).optional(), + sku: z.union([z.string(), z.array(z.string())]).optional(), + options: z + .object({ value: z.string().optional(), option_id: z.string().optional() }) + .optional(), created_at: createOperatorMap().optional(), updated_at: createOperatorMap().optional(), deleted_at: createOperatorMap().optional(), @@ -64,10 +67,12 @@ export const StoreGetProductsParams = createFindParams({ z .object({ variants: z - .object({ options: z - .object({ value: z.string().optional(), option_id: z.string().optional() }) + .object({ + value: z.string().optional(), + option_id: z.string().optional(), + }) .optional(), }) .merge(applyAndAndOrOperators(StoreGetProductVariantsParamsFields))