feat(product): add SKU search support to admin API#13930
feat(product): add SKU search support to admin API#13930bqst wants to merge 4 commits intomedusajs:developfrom
Conversation
|
@bqst is attempting to deploy a commit to the medusajs Team on Vercel. A member of the Team first needs to authorize it. |
🦋 Changeset detectedLatest commit: e024914 The changes in this PR will be included in the next version bump. This PR includes changesets to release 74 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days. |
|
unstale |
|
This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days. |
|
unstale |
|
This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days. |
|
This PR was closed because it has been stalled for 5 days with no activity. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
This is the final PR Bugbot will review for you during this billing cycle
Your free Bugbot reviews will reset on March 17
Details
Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
| fromEntity: Product.name, | ||
| } | ||
| delete filters.q | ||
| } |
There was a problem hiding this comment.
Redundant free text search filter duplicates base service logic
Low Severity
The manually added free text search filter logic in listProducts and listAndCountProducts is entirely redundant. The underlying this.productService_.list() and this.productService_.listAndCount() already call applyFreeTextSearchFilter(filters, config) in the base MedusaInternalService, which performs the identical operation — checking filters.q, adding the same FreeTextSearchFilterKeyPrefix + model.name filter to config.filters, and deleting filters.q. The only change actually needed for SKU search is the .searchable() annotation on the variants relationship in the model. This duplication increases maintenance burden and risks divergence if the base service logic changes.
Additional Locations (1)
|
Thank you for your contribution! After reviewing this PR, we need a few things addressed before we can move forward: Required changes:
Notes: Marking The implementation pattern follows |


Summary
What — What changes are introduced in this PR?
This PR adds the ability to search products by their variant SKU through the admin
/admin/productsendpoint using the q query parameter. Products can now be found by searching for exact or partial SKU matches across all product variants.Note: This feature was available in Medusa v1 but was missing in v2, causing friction for users migrating from v1 or integrating with external systems.
Why — Why are these changes relevant or necessary?
Critical for WMS/ERP Integration and Internal Operations:
How — How have these changes been implemented?
The implementation leverages Medusa's existing free text search infrastructure:
Product Model (
packages/modules/product/src/models/product.ts):variantsrelationship as.searchable()to enable search traversal into product variantsProduct Module Service (
packages/modules/product/src/services/product-module-service.ts):FreeTextSearchFilterKeyPrefiximportlistProducts()method whenqparameter is presentlistAndCountProducts()method whenqparameter is presentSearch Behavior:
?q=ABCwill find"ABC-123","TEST-ABC-XYZ", etc.Testing — How have these changes been tested, or how can the reviewer test the feature?
Comprehensive integration tests have been added in
integration-tests/http/__tests__/product/admin/product-sku-search.spec.ts:✅ All 6 tests passing:
To test manually:
Checklist
Please ensure the following before requesting a review:
yarn changesetand follow the promptsAdditional Context
Note
Medium Risk
Changes product listing query behavior by introducing free-text search traversal across variants, which may affect result sets and query performance on large catalogs; covered by integration tests.
Overview
Adds support for free-text searching products by variant SKU (and other searchable variant fields) via the admin
GET /admin/products?q=...endpoint by wiringqinto the module’s free-text search filter.This marks the
Product.variantsrelation as.searchable()to allow search traversal into variants, and updateslistProducts/listAndCountProductsto translatefilters.qinto aFreeTextSearchFilterKeyPrefix + Productfilter (removingqfrom the remaining filters). Integration tests are added to cover exact/partial SKU matching, multi-variant results, combined title+SKU search, non-matches, and case-insensitivity.Written by Cursor Bugbot for commit e024914. This will update automatically on new commits. Configure here.