From 9af4dd44bfd93b661950e63e49cf42bc5995d778 Mon Sep 17 00:00:00 2001 From: Konstantin Savosteev Date: Wed, 23 Oct 2024 21:31:56 +0200 Subject: [PATCH] VCST-2009: single value variations fix (#18) * a single variation not return issue fixed VariationBinder was not return the variation id if it was a single value * fix: refactor --------- Co-authored-by: AhmedElrakhawy <106417327+AhmedElrakhawy@users.noreply.github.com> Co-authored-by: Kutasina Elena <62027488+ekuvirto@users.noreply.github.com> --- .../Binding/VariationsBinder.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/VirtoCommerce.XCatalog.Core/Binding/VariationsBinder.cs b/src/VirtoCommerce.XCatalog.Core/Binding/VariationsBinder.cs index 85efb20..a35800d 100644 --- a/src/VirtoCommerce.XCatalog.Core/Binding/VariationsBinder.cs +++ b/src/VirtoCommerce.XCatalog.Core/Binding/VariationsBinder.cs @@ -12,9 +12,16 @@ public virtual object BindModel(SearchDocument searchDocument) { var fieldName = BindingInfo.FieldName; - return searchDocument.TryGetValue(fieldName, out var value) && value is object[] objs - ? objs.Select(x => (string)x).ToList() - : Enumerable.Empty().ToList(); + var result = searchDocument.TryGetValue(fieldName, out var value) + ? value switch + { + object[] objs => objs.Select(x => (string)x).ToList(), + string str => [str], + _ => Enumerable.Empty().ToList() + } + : Enumerable.Empty().ToList(); + + return result; } } }