medusajs / medusa

The world's most flexible commerce platform.
https://medusajs.com
MIT License
25.71k stars 2.56k forks source link

Filtering products based on category_id and q parameter bug #4885

Closed quiloos39 closed 1 year ago

quiloos39 commented 1 year ago

Between Medusa version 1.13.x - 1.15.x there seems to be bug where client is unable to filter by both category_id and q parameters. Using only category_id or q works but cannot use both of them.

medusa-config.js

  // ...
  featureFlags: {
    product_categories: true,
  }

Example API call GET http://localhost:9000/store/products?category_id[]=pcat_01H8XER1K4MRXX9RZTN2TTY7VA&q=coffee

API response:

{
    "code": "unknown_error",
    "type": "unknown_error",
    "message": "An unknown error occurred."
}

Backend Terminal:

Property "category_id" was not found in "Product". Make sure your query is correct.
EntityPropertyNotFoundError: Property "category_id" was not found in "Product". Make sure your query is correct.
    at SelectQueryBuilder.findColumnsForPropertyPath (/home/necdet/Documents/work/traumkaffee/packages/backend/node_modules/typeorm/query-builder/QueryBuilder.js:899:19)
    at SelectQueryBuilder.getPredicates (/home/necdet/Documents/work/traumkaffee/packages/backend/node_modules/typeorm/query-builder/QueryBuilder.js:973:66)
    at getPredicates.next (<anonymous>)
    at SelectQueryBuilder.getWhereCondition (/home/necdet/Documents/work/traumkaffee/packages/backend/node_modules/typeorm/query-builder/QueryBuilder.js:1104:50)
    at SelectQueryBuilder.where (/home/necdet/Documents/work/traumkaffee/packages/backend/node_modules/typeorm/query-builder/SelectQueryBuilder.js:342:32)
    at Object.<anonymous> (/home/necdet/Documents/work/traumkaffee/packages/backend/node_modules/@medusajs/medusa/dist/repositories/product.js:421:30)
    at step (/home/necdet/Documents/work/traumkaffee/packages/backend/node_modules/@medusajs/medusa/dist/repositories/product.js:44:23)
    at Object.next (/home/necdet/Documents/work/traumkaffee/packages/backend/node_modules/@medusajs/medusa/dist/repositories/product.js:25:53)
    at /home/necdet/Documents/work/traumkaffee/packages/backend/node_modules/@medusajs/medusa/dist/repositories/product.js:19:71
    at new Promise (<anonymous>)
riqwan commented 1 year ago

Thanks for surfacing this @quiloos39!

I've opened a PR to fix this, can you try with this snapshot?

yarn add @medusajs/medusa@1.15.1-snapshot-20230828104214

quiloos39 commented 1 year ago

Thanks for the fast fix, it seems to be working. I will deploy this into our development environment to test it further.