public static ProductResult GetProductResult(DWProduct product) { var productResult = new ProductResult(); productResult.Products.Add(product); return(productResult); }
private void DwSetProductRating(ICore _core, DWProduct product) { try { if (product.ReviewCount > 0) { var avgrating = GetPwAvgRate(_core, product.Id); if (avgrating.Any()) { var firstOrDefault = avgrating.FirstOrDefault(); if (firstOrDefault != null) { product.AverageRating = decimal.Parse(firstOrDefault.average_rating); } } ProductRating = new ProductRatingBase { NumberOfTimesRated = product.ReviewCount, Rating = product.AverageRating }; } } catch (Exception ex) { _errors.Add(ex.Handle("Product.DWSetProductRating", ErrorSeverity.FollowUp, ErrorType.RequestError)); } }
private DWProduct ReplaceColors(DWProduct product) { try { var colorVariations = _request.Products.Where(p => p.ProductId == product.Id).Select(v => v.AvailableVariations.FirstOrDefault()); product.VariationAttributes.RemoveAll(p => p.Id == "color"); product.VariationAttributes.AddRange(colorVariations.ToList()); product.VariationAttributes.Reverse(); } catch (Exception) {} return(product); }
private DWImage GetImagesForColor(DWProduct product, string color) { var images = product.ImageGroups.Where(z => z.ViewType == "hi-res" && z.VariationAttributes.Any(e => e.values.Any((v => v.value == color)))) .Select(z => z.Images) .FirstOrDefault(); if (images != null) { return new DWImage() { Alt = images[0].Alt, Title = images[0].Title, Link = images[0].Link.Replace("/aapr_prd/", "/sits_pod15/dw/image/v2/AAPR_PRD/") + "?sw=200" } } ; else { return(null); } }
private DWImage GetSwatchImage(DWProduct product, string color) { //This is an alternative way in case linq failed -by Carlos SPAY-404 //var swatchImages = new List<DWImage>(); //foreach (var imageViewType in product.ImageGroups) //{ // if (imageViewType.ViewType.Equals("swatch")) // { // foreach (var image in imageViewType.Images) // { // if (image.Link.ToLower().Contains(color.Replace("_", "").ToLower())) // return new DWImage() { Link = image.Link, Alt = image.Alt, Title = image.Title }; // } // } //} var swatchImages = product.ImageGroups.Where(z => z.ViewType == "swatch" && z.VariationAttributes.Any(e => e.values.Any((v => v.value == color)))) .Select(z => z.Images) .FirstOrDefault(); if (swatchImages != null) { foreach (var image in swatchImages) { if (image.Link.ToLower().Contains(color.Replace("_", "").ToLower())) { return new DWImage() { Link = image.Link, Alt = image.Alt, Title = image.Title } } ; } } return(null); }
public ProductDetailResponse(DWProduct product, string color, ICore core, List <SiteError> errors) { RequestedColor = color; Product = new Product(product, color, core, errors); }
public Product(DWProduct product, string color, ICore _core, List <SiteError> errors) : this() { AdditionalInfo = product.CustomerService; CareInstructions = product.CareInstructions; Description = product.ShortDescription; Name = product.Name; Brand = product.Brand; Category = product.PrimaryCategoryId ?? ""; ProductId = product.Id; ProductFlags = LookupCallouts(product.ProductFlags); Promotions = product.Promotions.Where(a => !string.IsNullOrEmpty(a.Callout)).ToList(); IsInStore = product.IsInStore == null || product.IsInStore == true; if (!string.IsNullOrEmpty(product.PrimaryCategoryId)) { BreadCrumb = RecommendedProducts.Load(product.Id, _core).Breadcrumb; } var price = new Price(product.Price.ToString(CultureInfo.InvariantCulture)); if (product.Price == 0 && product.Variants != null) { price = new Price(product.Variants[0].Price.ToString()); } if (product.MaxPrice > 0) { var maxPrice = new Price(product.MaxPrice.ToString()); price.Label = maxPrice.Formatted; } Pricing.Add(price); Image = new Image { Title = product.Brand }; if (!string.IsNullOrEmpty(product.DisplayBrand)) { var cms = new PaylessMadCms(_core); var brandImages = cms.BrandImageLookup(); if (brandImages.ContainsKey(product.DisplayBrand)) { var brandImage = brandImages[product.DisplayBrand]; Image.Src = string.Format(Config.Urls.BrandImageTemplate, brandImage); } } var variants = product.Variants; if (variants != null) { VariantIdsSegments = variants.Select((x, i) => new { x, i }) .GroupBy(x => x.i / 50) .Select(x => string.Join(",", x.Select(y => y.x.ProductId))) .ToList(); AvailableVariations = product.VariationAttributes; var isGiftCard = product.Brand != null && product.Brand == "GIFT CARD"; if (AvailableVariations != null) { var sizeVariations = AvailableVariations.Find(x => x.Id == "size" && x.Values.Any()); var isOneSizeOnly = (sizeVariations != null && sizeVariations.Values.Count.Equals(1) && sizeVariations.Values.First().Name == "One Size") || (sizeVariations == null); if (product.ImageGroups != null) { var imageGroups = product.ImageGroups; var swatchImages = DwSwatchImages(imageGroups); var colorVariations = DWColorVariationAttribute(); SetSelectedColorValue(color, colorVariations, swatchImages, imageGroups, variants, isOneSizeOnly, isGiftCard); var designVariations = DwDesignVariationAttribute(); if (designVariations != null) { DWGetDesignValues(designVariations, imageGroups, variants); if (Designs.Any()) { var firstOrDefault = Designs.FirstOrDefault(); if (firstOrDefault != null) { firstOrDefault.IsSelected = true; } } } } } } DwSetProductRating(_core, product); VideoID = product.InvodoVideoExists ? ProductId : null; }