private VariationAttribute DwDesignVariationAttribute() { var designVariations = new VariationAttribute(); try { if (AvailableVariations != null) { designVariations = AvailableVariations.Find(x => x.Id == "design" && x.Values.Any()); } } catch (Exception ex) { _errors.Add(ex.Handle("Product.DWDesignVariationAttribute", ErrorSeverity.FollowUp, ErrorType.RequestError)); return(designVariations); } return(designVariations); }
private VariationAttribute DWColorVariationAttribute() { var colorVariations = new VariationAttribute(); try { if (AvailableVariations != null) { colorVariations = AvailableVariations.Find(x => x.Id == "color" && x.Values.Any()); } } catch (Exception ex) { _errors.Add(ex.Handle("Product.ColorImages", ErrorSeverity.FollowUp, ErrorType.RequestError)); return(new VariationAttribute()); } return(colorVariations); }
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; }