Skip to content

fix(vtex): filter undefined products from sortProducts - #1611

Open
guitavano wants to merge 1 commit into
mainfrom
fix/vtex-sort-products-undefined
Open

fix(vtex): filter undefined products from sortProducts#1611
guitavano wants to merge 1 commit into
mainfrom
fix/vtex-sort-products-undefined

Conversation

@guitavano

@guitavano guitavano commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • When requesting products by SKU IDs via intelligentSearch/productList.ts, if a SKU doesn't exist or is inactive, the VTEX API omits it from the response
  • The sortProducts function maps over the original ID list, which resulted in undefined entries for missing SKUs
  • Added .filter(Boolean) to remove undefined entries from the returned array

Test plan

  • Configure a product shelf with SKU IDs where at least one is inactive/nonexistent
  • Verify the loader returns only valid products without undefined entries
  • Verify the remaining products maintain the original order

🤖 Generated with Claude Code


Summary by cubic

Fixes VTEX product sorting when requesting by SKU IDs by removing undefined entries for missing/inactive SKUs, preserving the order of valid products. Implemented by adding .filter(Boolean) to sortProducts in vtex/utils/transform.ts.

Written for commit 10efdbd. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Fixed product sorting to exclude missing or unavailable products from results. Undefined entries that appeared when requested products weren't found are now properly filtered out, providing cleaner and more reliable output.

When requesting products by SKU IDs, if a SKU doesn't exist or is
inactive in VTEX, the API simply omits it from the response. The
sortProducts function was mapping over the original ID list, resulting
in undefined entries for missing SKUs. Added filter(Boolean) to remove
those entries.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Tagging Options

Should a new tag be published when this PR is merged?

  • 👍 for Patch 0.158.1 update
  • 🎉 for Minor 0.159.0 update
  • 🚀 for Major 1.0.0 update

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0353181a-6f10-4c00-8900-9ddaddf09cfe

📥 Commits

Reviewing files that changed from the base of the PR and between 192c63c and 10efdbd.

📒 Files selected for processing (1)
  • vtex/utils/transform.ts

📝 Walkthrough

Walkthrough

In sortProducts within vtex/utils/transform.ts, the final .map() call over orderOfIdsOrSkus now chains a .filter(Boolean) (or equivalent falsy filter) to strip undefined entries that arise when a requested product id or SKU is not present in productMap.

Changes

sortProducts undefined filtering

Layer / File(s) Summary
Filter undefined from sortProducts output
vtex/utils/transform.ts
The .map() over orderOfIdsOrSkus now filters out falsy values, so the returned array no longer contains undefined elements for unmatched ids/skus.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

A rabbit sorts products with care and delight,
But undefined entries? They just weren't right!
One filter added, one character more,
No ghostly undefined in the array anymore.
🐇✨ Clean arrays ahead, hop hop hooray!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: filtering undefined products from the sortProducts function.
Description check ✅ Passed The description provides comprehensive context about the issue, the solution, and a test plan. It covers the problem (undefined entries for missing SKUs), the fix (.filter(Boolean)), and verification steps.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/vtex-sort-products-undefined

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Re-trigger cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant