Skip to content

Commit 25626bd

Browse files
committed
updates to handle no options
Former-commit-id: a8aaf09a25c3eb670a23d616b2d0e79902ef6d53
1 parent 577ff9d commit 25626bd

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

STOREFRONT/WebModels/Convertors/ProductConverters.cs

+20-3
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ public static Product AsWebModel(
115115

116116
var variant = product.AsVariantWebModel(productPrice, options, productRewards, productInventory);
117117

118+
variant.Title = "Default Title";
119+
118120
productModel.Variants.Add(variant);
119121

120122
return productModel;
@@ -148,7 +150,7 @@ public static Variant AsVariantWebModel(this Data.CatalogItem variation, Data.Pr
148150
variantModel.Image = variationImage != null ? variationImage.AsWebModel(variation.Name, variation.MainProductId) : null;
149151

150152
PopulateInventory(ref variantModel, variation, inventory);
151-
variantModel.AllOptions = GetOptionValues(options, variation.VariationProperties);
153+
variantModel.Options = GetOptionValues(options, variation.VariationProperties);
152154

153155
variantModel.NumericPrice = price != null ? (price.Sale.HasValue ? price.Sale.Value : price.List) : 0M;
154156
if (reward != null)
@@ -219,18 +221,32 @@ public static Review AsWebModel(this Data.Review review)
219221
return webReview;
220222
}
221223

224+
#region Option Methods
225+
226+
private static string DefaultOption = "Default Title";
222227
private static string[] GetOptions(IDictionary<string, object> itemProperties)
223228
{
224229
if (itemProperties == null || !itemProperties.Any())
225230
{
226-
return null;
231+
return new []{ "Title" };
227232
}
228233

229-
return itemProperties.Select(o => o.Key).ToArray();
234+
var options = itemProperties.Select(o => o.Key).ToArray();
235+
if (options == null || !options.Any())
236+
{
237+
options = new[] { "Title" };
238+
}
239+
240+
return options;
230241
}
231242

232243
private static string[] GetOptionValues(IEnumerable<string> options, IDictionary<string, object> itemProperties)
233244
{
245+
if (options != null && options.Count() == 1 && options.ElementAt(0) == "Title")
246+
{
247+
return new[] { DefaultOption };
248+
}
249+
234250
if (itemProperties == null || !itemProperties.Any() || options == null)
235251
{
236252
return null;
@@ -239,6 +255,7 @@ private static string[] GetOptionValues(IEnumerable<string> options, IDictionary
239255
var variationOptions = options.Select(option => itemProperties.ContainsKey(option) ? itemProperties[option].ToNullOrString() : null).ToList();
240256
return variationOptions.ToArray();
241257
}
258+
#endregion
242259

243260
private static UrlHelper GetUrlHelper()
244261
{

STOREFRONT/WebModels/Models/Variant.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ public Image FeaturedImage
7070
public long InventoryQuantity { get; set; }
7171

7272
[DataMember]
73-
public string[] AllOptions { get; set; }
73+
public string[] Options { get; set; }
7474

7575
[DataMember]
7676
public string Option1
7777
{
7878
get
7979
{
80-
if (this.AllOptions == null) return null;
81-
return this.AllOptions.Length >= 1 ? this.AllOptions[0] : null;
80+
if (this.Options == null) return null;
81+
return this.Options.Length >= 1 ? this.Options[0] : null;
8282
}
8383
}
8484

@@ -87,8 +87,8 @@ public string Option2
8787
{
8888
get
8989
{
90-
if (this.AllOptions == null) return null;
91-
return this.AllOptions.Length >= 2 ? this.AllOptions[1] : null;
90+
if (this.Options == null) return null;
91+
return this.Options.Length >= 2 ? this.Options[1] : null;
9292
}
9393
}
9494

@@ -97,8 +97,8 @@ public string Option3
9797
{
9898
get
9999
{
100-
if (this.AllOptions == null) return null;
101-
return this.AllOptions.Length >= 3 ? this.AllOptions[2] : null;
100+
if (this.Options == null) return null;
101+
return this.Options.Length >= 3 ? this.Options[2] : null;
102102
}
103103
}
104104

0 commit comments

Comments
 (0)