public IHttpActionResult GetVariantSkuFromSelectionRequest([FromBody] GetVariantSkuFromSelectionRequest request)
        {
            var product = CatalogLibrary.GetProduct(request.ProductSku);

            UCommerce.EntitiesV2.Product variant = null;

            if (product.Variants.Any() && request.VariantProperties.Any()) // If there are variant values we'll need to find the selected variant
            {
                variant = product.Variants.FirstOrDefault(v => v.ProductProperties.Where(pp => pp.ProductDefinitionField.DisplayOnSite && pp.ProductDefinitionField.IsVariantProperty && !pp.ProductDefinitionField.Deleted && pp.Value != null && pp.Value != String.Empty).All(p => request.VariantProperties.Any(kv => kv.Key.Equals(p.ProductDefinitionField.Name, StringComparison.InvariantCultureIgnoreCase) && kv.Value.ToString().Equals(p.Value, StringComparison.InvariantCultureIgnoreCase))));
            }
            else if (!product.Variants.Any()) // Only use the current product where there are no variants
            {
                variant = product;
            }

            var variantModel = new ProductVariation
            {
                Sku         = variant.Sku,
                VariantSku  = variant.VariantSku,
                ProductName = variant.Name,
                Properties  = variant.ProductProperties.Select(prop => new ProductProperty
                {
                    Id    = prop.Id,
                    Name  = prop.ProductDefinitionField.Name,
                    Value = prop.Value
                })
            };

            return(Json(new { Variant = variantModel }));
        }
        public IHttpActionResult GetVariantSkuFromSelectionRequest([FromBody] GetVariantSkuFromSelectionRequest request)
        {
            var     product = CatalogLibrary.GetProduct(request.ProductSku);
            Product variant = null;

            if (product.ProductType == ProductType.ProductFamily && request.VariantProperties.Any()
                ) // If there are variant values we'll need to find the selected variant
            {
                var query = ProductsIndex.Find().Where(p => p.Sku == request.ProductSku && p.ProductType == ProductType.Variant);
                request.VariantProperties.ForEach(property =>
                {
                    query = query.Where(p => p[property.Key] == property.Value);
                });
                variant = query.FirstOrDefault();
            }
            else if (!product.Variants.Any()) // Only use the current product where there are no variants
            {
                variant = product;
            }

            if (variant == null)
            {
                return(NotFound());
            }

            var variantModel = new ProductVariation
            {
                Sku         = variant.Sku,
                VariantSku  = variant.VariantSku,
                ProductName = variant.Name,
            };

            return(Json(new { Variant = variantModel }));
        }