-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(product-sync): fix matching variants (#273)
#### Summary Fix how we match variants. #### Description Originally, we were matching variants in a single loop by comparing id, sku or key. Because we used id as a primary matching condition, there was happening, that we matched variants with the same ids but with different skus which later failed due to a duplicate slug error. For example when syncing these two products: ```js // existing product { masterVariant: { id: 1, sku: "sku1" }, variants: [{ id: 2, sku: "sku3" }, { id: 3, sku: "sku2" }] } // and new product { masterVariant: { id: 1, sku: "sku1" }, variants: [{ id: 2, sku: "sku2" }, { id: 3, sku: "sku3" }] } ``` It would match variants using id and generate update actions: ```js [{ action: "setSku", variantId: 2, sku: "sku2" }, { action: "setSku", variantId: 3, sku: "sku3" }] ``` Which would fail because we can't set `sku2` to the first variant because it already exists. Therefore we should match by skus, then by keys and then, as a fallback, by id. #### Todo - Tests - [x] Unit - [ ] Integration - [ ] Acceptance - [ ] Documentation <!-- Two persons should review a PR, don't forget to assign them. -->
- Loading branch information
Showing
5 changed files
with
115 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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