Skip to content

Commit

Permalink
fix(medusa): Allow filtering by handle and title as arrays (#11472)
Browse files Browse the repository at this point in the history
**What**
- Allows filtering products in the Store API with an array value for both `handle` and `title`.

RESOLVES SUP-893
  • Loading branch information
kasperkristensen authored Feb 14, 2025
1 parent 9f39cd1 commit 825b8ad
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/loud-pets-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---

fix(medusa): Allow filtering products by handle and title as either string or array of strings
28 changes: 28 additions & 0 deletions integration-tests/http/__tests__/product/store/product.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,34 @@ medusaIntegrationTestRunner({
])
})

it("returns a list of products with one of the given handles", async () => {
const response = await api.get(
`/store/products?handle[]=${product.handle}&handle[]=${product2.handle}`,
storeHeaders
)

expect(response.status).toEqual(200)
expect(response.data.count).toEqual(2)
expect(response.data.products).toEqual([
expect.objectContaining({ id: product.id }),
expect.objectContaining({ id: product2.id }),
])
})

it("returns a list of products with one of the given titles", async () => {
const response = await api.get(
`/store/products?title[]=${product.title}&title[]=${product2.title}`,
storeHeaders
)

expect(response.status).toEqual(200)
expect(response.data.count).toEqual(2)
expect(response.data.products).toEqual([
expect.objectContaining({ id: product.id }),
expect.objectContaining({ id: product2.id }),
])
})

// TODO: Not implemented yet
it.skip("returns gift card product", async () => {
const response = await api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const ProductStatusEnum = z.nativeEnum(ProductStatus)
export const StoreGetProductParamsDirectFields = z.object({
q: z.string().optional(),
id: z.union([z.string(), z.array(z.string())]).optional(),
title: z.string().optional(),
handle: z.string().optional(),
title: z.union([z.string(), z.array(z.string())]).optional(),
handle: z.union([z.string(), z.array(z.string())]).optional(),
is_giftcard: booleanString().optional(),
category_id: z.union([z.string(), z.array(z.string())]).optional(),
external_id: z.union([z.string(), z.array(z.string())]).optional(),
Expand Down

0 comments on commit 825b8ad

Please sign in to comment.