Skip to content

fix: assign facets to channel when re-importing products via CSV#4713

Open
Ryrahul wants to merge 1 commit into
vendurehq:masterfrom
Ryrahul:fix/import-facets-channel-assignment
Open

fix: assign facets to channel when re-importing products via CSV#4713
Ryrahul wants to merge 1 commit into
vendurehq:masterfrom
Ryrahul:fix/import-facets-channel-assignment

Conversation

@Ryrahul
Copy link
Copy Markdown
Contributor

@Ryrahul Ryrahul commented May 9, 2026

Fixes #4673

Description

When importing products via CSV into a newly created channel (after the same CSV was already imported into the default channel), facets and variantFacets were missing from the imported products.

Root cause: The Importer is a singleton, so its facetMap and facetValueMap caches persisted across import calls. On the second import, cached facet entities were reused without being assigned to the new channel. Additionally, when findByCode() found an existing facet (global lookup, no channel filter), the importer reused it without calling assignToChannels() — so the facet/facet-value entities were never associated with the new channel. The product resolver's findByIdsInChannel() then filtered them out, returning empty arrays.

Fix:

  • Clear facetMap, facetValueMap, and taxCategoryMatches caches at the start of each importProducts() call
  • Call channelService.assignToChannels() for existing facets and facet values found via findByCode(), ensuring they are assigned to the current import channel

Breaking changes

None.

Checklist

📌 Always:

  • I have set a clear title
  • My PR is small and contains a single feature
  • I have checked my own PR

👍 Most of the time:

  • I have added or updated test cases
  • I have updated the README if needed

View in Codesmith
Need help on this PR? Tag @codesmith with what you need.

  • Let Codesmith autofix CI failures and bot reviews

@vercel
Copy link
Copy Markdown

vercel Bot commented May 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
vendure-storybook Ready Ready Preview, Comment May 9, 2026 9:15am

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 9, 2026

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c94f3472-1e3c-4baa-aae5-022f64187b45

📥 Commits

Reviewing files that changed from the base of the PR and between 77212e3 and 4923748.

📒 Files selected for processing (2)
  • packages/core/e2e/import.e2e-spec.ts
  • packages/core/src/data-import/providers/importer/importer.ts

📝 Walkthrough

Walkthrough

This PR fixes a bug where facets and variantFacets were not being imported when re-importing products into newly created channels. The importer now clears internal caches (facetMap, facetValueMap, and taxCategoryMatches) at the start of each import run to prevent stale entity references. Additionally, when an existing Facet or FacetValue is discovered during import, it is now explicitly assigned to the current channel via channelService.assignToChannels(). A new e2e test validates the fix by creating a second channel, re-importing the same products CSV, and verifying that both product-level and variant-level facet values are present in the new channel.

Possibly related PRs

  • vendurehq/vendure#4618: Both PRs add explicit channelService.assignToChannels() calls to ensure entities are assigned to channels; this PR applies the pattern to Facet and FacetValue in the importer.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: assigning facets to a channel during product re-import via CSV.
Description check ✅ Passed The description comprehensively covers the root cause, the fix implemented, includes the issue reference, addresses breaking changes, and confirms test additions per the template checklist.
Linked Issues check ✅ Passed The PR fully addresses issue #4673 by fixing the missing facet/variantFacet assignment through cache clearing and channelService.assignToChannels() calls.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the facet assignment issue; cache clearing, channel assignment logic, and e2e test additions are all within scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

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.

Importer.importProducts does not assign facets/variantFacets on subsequent imports to new channels

1 participant