From e5ad0ee23948bfe0af436e08c1a6ff0c64c196a1 Mon Sep 17 00:00:00 2001 From: Michael Bromley Date: Fri, 11 Aug 2023 09:02:57 +0200 Subject: [PATCH] fix(admin-ui): Fix error when saving multiple new variant options Fixes #2326 --- .../product-variants-editor.component.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/admin-ui/src/lib/catalog/src/components/product-variants-editor/product-variants-editor.component.ts b/packages/admin-ui/src/lib/catalog/src/components/product-variants-editor/product-variants-editor.component.ts index 4135d972b3..5caae54941 100644 --- a/packages/admin-ui/src/lib/catalog/src/components/product-variants-editor/product-variants-editor.component.ts +++ b/packages/admin-ui/src/lib/catalog/src/components/product-variants-editor/product-variants-editor.component.ts @@ -15,6 +15,7 @@ import { SelectionManager, } from '@vendure/admin-ui/core'; import { normalizeString } from '@vendure/common/lib/normalize-string'; +import { unique } from '@vendure/common/lib/unique'; import { EMPTY, Observable, Subject } from 'rxjs'; import { map, startWith, switchMap } from 'rxjs/operators'; @@ -296,14 +297,15 @@ export class ProductVariantsEditorComponent implements OnInit, DeactivateAware { } addOptionToVariant(variant: NonNullable['variants'][number]) { + const optionIds = [ + ...variant.options.map(o => o.id), + ...Object.values(this.optionsToAddToVariant[variant.id]), + ]; this.dataService.product .updateProductVariants([ { id: variant.id, - optionIds: [ - ...variant.options.map(o => o.id), - ...Object.values(this.optionsToAddToVariant[variant.id]), - ], + optionIds: unique(optionIds), }, ]) .subscribe(({ updateProductVariants }) => {