Exemple #1
0
        private Response <ProductDetailResponse> GetResponse(DWClientConfig config)
        {
            var result = new Response <ProductDetailResponse>();

            try
            {
                var apiResponse = DWClient.GetAPIResponse <DWProduct>(config);
                if (apiResponse.ResponseStatus.Code == HttpStatusCode.OK)
                {
                    result.resultset = new ProductDetailResponse(apiResponse.Model, _request.Color, _core, _errors);
                    try
                    {
                        result.resultset.RecommendedProducts = RecommendedProducts.Load(result.resultset.Product.ProductId, _core).Products;
                    }
                    catch
                    {
                        // ignored
                    }
                    result.template = Config.ResponseTemplates.ProductDetail;
                    var reviewsObj = GetPwReviews(result.resultset.Product.ProductId);
                    result.resultset.Product.PowerReview.Reviews    = reviewsObj.Item1;
                    result.resultset.Product.PowerReview.Pagination = reviewsObj.Item2;
                    result.resultset.Product.PowerReview.Snapshot   = GetPwSnapShots(result.resultset.Product.ProductId);
                    result.resultset.Product.PowerReview.MsqcTags   = PowerReviewHelper.GetMsqcsTagSummary(result.resultset.Product.PowerReview.Reviews);
                    result.resultset.Product.PowerReview.FaceOff    = GetPwFaceOff(result.resultset.Product.ProductId);
                    if (!string.IsNullOrWhiteSpace(result.resultset.Product.PowerReview.Snapshot.average_rating))
                    {
                        result.resultset.Product.ProductRating.Rating = decimal.Parse(result.resultset.Product.PowerReview.Snapshot.average_rating);
                    }
                    if (result.resultset.Product.VariantIdsSegments.Count > 0)
                    {
                        IEnumerable <KeyValuePair <string, ProductDetailItemExtension> > tempDictionary = new Dictionary <string, ProductDetailItemExtension>();
                        result.resultset.Product.VariantIdsSegments.ForEach(segment =>
                        {
                            var variantIdToExtension = GetDetailExtension(segment);
                            tempDictionary           = tempDictionary.Union(variantIdToExtension);
                        });

                        if (!_errors.Any())
                        {
                            var completeDictionary = tempDictionary.GroupBy(x => x.Key).ToDictionary(x => x.Key, x => x.First().Value);

                            if (completeDictionary.Any())
                            {
                                result.resultset.Product.Colors.ForEach(color =>
                                {
                                    color.Sizes.ForEach(size =>
                                    {
                                        if (completeDictionary.ContainsKey(size.Value))
                                        {
                                            size.SizeSegment  = completeDictionary[size.Value].SizeSegment;
                                            size.ExclusiveMsg = completeDictionary[size.Value].ExclusiveMsg;
                                            size.PriceRange   = completeDictionary[size.Value].PriceRange;
                                        }
                                        color.SizeSegments = color.Sizes
                                                             .Where(x => !string.IsNullOrEmpty(x.SizeSegment))
                                                             .GroupBy(x => x.SizeSegment)
                                                             .Select((x, i) => new Option
                                        {
                                            Name       = x.First().SizeSegment,
                                            Value      = x.First().SizeSegment,
                                            IsSelected = i == 0
                                        })
                                                             .ToList();
                                    });
                                    color.Sizes = color.Sizes;
                                });
                            }
                        }
                    }
                    result.resultset.Product.Pricing = ProductPricing.GetByID(_core, _request.Id);
                }
                else
                {
                    _errors.Add(new SiteError
                    {
                        Message = new ErrorMessage(Config.Constants.GenericError, apiResponse.ResponseStatus.Message)
                    });
                }
            }
            catch (Exception ex)
            {
                var titleMsg = string.Format("ProductDetail.GetResponse - DW Productid: {0}-{1}", result.resultset.Product.ProductId, config.Path);
                _errors.Add(ex.Handle(titleMsg, ErrorSeverity.FollowUp, ErrorType.RequestError));
            }
            return(result);
        }
Exemple #2
0
        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;
        }