Skip to content

Commit

Permalink
updates to handle no options
Browse files Browse the repository at this point in the history
Former-commit-id: a8aaf09a25c3eb670a23d616b2d0e79902ef6d53
  • Loading branch information
Woland2k committed Jul 2, 2015
1 parent 577ff9d commit 25626bd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
23 changes: 20 additions & 3 deletions STOREFRONT/WebModels/Convertors/ProductConverters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ public static Product AsWebModel(

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

variant.Title = "Default Title";

productModel.Variants.Add(variant);

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

PopulateInventory(ref variantModel, variation, inventory);
variantModel.AllOptions = GetOptionValues(options, variation.VariationProperties);
variantModel.Options = GetOptionValues(options, variation.VariationProperties);

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

#region Option Methods

private static string DefaultOption = "Default Title";
private static string[] GetOptions(IDictionary<string, object> itemProperties)
{
if (itemProperties == null || !itemProperties.Any())
{
return null;
return new []{ "Title" };
}

return itemProperties.Select(o => o.Key).ToArray();
var options = itemProperties.Select(o => o.Key).ToArray();
if (options == null || !options.Any())
{
options = new[] { "Title" };
}

return options;
}

private static string[] GetOptionValues(IEnumerable<string> options, IDictionary<string, object> itemProperties)
{
if (options != null && options.Count() == 1 && options.ElementAt(0) == "Title")
{
return new[] { DefaultOption };
}

if (itemProperties == null || !itemProperties.Any() || options == null)
{
return null;
Expand All @@ -239,6 +255,7 @@ private static string[] GetOptionValues(IEnumerable<string> options, IDictionary
var variationOptions = options.Select(option => itemProperties.ContainsKey(option) ? itemProperties[option].ToNullOrString() : null).ToList();
return variationOptions.ToArray();
}
#endregion

private static UrlHelper GetUrlHelper()
{
Expand Down
14 changes: 7 additions & 7 deletions STOREFRONT/WebModels/Models/Variant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ public Image FeaturedImage
public long InventoryQuantity { get; set; }

[DataMember]
public string[] AllOptions { get; set; }
public string[] Options { get; set; }

[DataMember]
public string Option1
{
get
{
if (this.AllOptions == null) return null;
return this.AllOptions.Length >= 1 ? this.AllOptions[0] : null;
if (this.Options == null) return null;
return this.Options.Length >= 1 ? this.Options[0] : null;
}
}

Expand All @@ -87,8 +87,8 @@ public string Option2
{
get
{
if (this.AllOptions == null) return null;
return this.AllOptions.Length >= 2 ? this.AllOptions[1] : null;
if (this.Options == null) return null;
return this.Options.Length >= 2 ? this.Options[1] : null;
}
}

Expand All @@ -97,8 +97,8 @@ public string Option3
{
get
{
if (this.AllOptions == null) return null;
return this.AllOptions.Length >= 3 ? this.AllOptions[2] : null;
if (this.Options == null) return null;
return this.Options.Length >= 3 ? this.Options[2] : null;
}
}

Expand Down

0 comments on commit 25626bd

Please sign in to comment.