Fix: cascade CatalogId to descendants and products on cross-catalog category move (cut & paste)#882
Open
yuskithedeveloper wants to merge 4 commits into
Open
Fix: cascade CatalogId to descendants and products on cross-catalog category move (cut & paste)#882yuskithedeveloper wants to merge 4 commits into
yuskithedeveloper wants to merge 4 commits into
Conversation
Contributor
|
Review task created: https://virtocommerce.atlassian.net/browse/VCST-5082 |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Description
Problem
Moving a category to a different catalog via the admin UI's Cut/Paste
(
POST /api/catalog/listentries/move) leaves the database in aninconsistent state: the selected
Category.CatalogIdis updated, butnothing else is. Specifically:
CatalogId, so an entiresubtree ends up belonging to a different catalog than its root.
CatalogId,so
Item.CatalogIdno longer matchesCategory.CatalogId.This breaks any feature that filters by
CatalogId(search, indexing,catalog-scoped property/dictionary lookups).
Cause
CategoryMover.PrepareMoveAsynconly iterates entries explicitlylisted in
ListEntriesMoveRequest.ListEntries(the user's selectionin the UI) and mutates
CatalogId/ParentIdon those rows alone.There is no traversal of the moved subtree, and
ProductMoveronlytouches products that were directly listed in the request — products
located inside a moved category are invisible to it.
Fix
CategoryMovernow cascades the catalog change. The change iscontained to a single file; controller, request DTO, and
ProductMoverare unchanged.PrepareMoveAsynccaptures the sourceCatalogIdof eachcross-catalog root, then loads each source catalog's category set
once via
ICategorySearchServiceand BFS-walks a parent→childrenmap to collect all descendants. Descendants get the target
CatalogIdand are appended to the returned list.ConfirmMoveAsyncsaves all categories (roots + descendants)and then cascades products. The target
CatalogIdand category idsare derived from the entities themselves — no instance fields, no
changes to the base mover signature.
CascadeProductsAsyncpages through products byCategoryIdswith
SearchInVariations = trueso variations are updated as flatresults, then saves each batch via
IItemService.SaveChangesAsync(which raises the existing domain events that trigger reindexing).
Same-catalog reparents are unchanged in behavior: no descendants are
added in
Prepare, and the product cascade inConfirmis a singlebounded search whose per-product
CatalogIdfilter yields no writes.Behavior considerations
CategoryMovergains three new dependencies (ICategorySearchService,IProductSearchService,IItemService). DI resolves themautomatically; no module wiring change is needed.
more work inside the HTTP request. The existing endpoint stays
synchronous; converting moves to a background job is left as a
follow-up.
IItemService.SaveChangesAsyncraises the usual
CatalogProductChangedEventand reindexing happensthrough the existing pipeline.
References
QA-test:
Jira-link:
Artifact URL: