Ejemplo n.º 1
0
        private IResponseBase GetResponse(DWClientConfig config, IRequestParameter parameters)
        {
            var theParams = (CartApplyCouponRequest)parameters;
            var result    = new Response <CheckoutResponse>();

            try
            {
                var apiResponse = DWClient.GetAPIResponse <CouponResponse>(config, true);

                if (apiResponse.ResponseStatus.Code == HttpStatusCode.OK)
                {
                    if (apiResponse.Model.success)
                    {
                        _core.CommunicationRequest = new ExtendedComRequest(HttpRequestMethod.GET, Config.Urls.ApplyBillingCouponPart2, _core, _errors);
                        var response = _core.RequestManager.Communicate(_core.CommunicationRequest);
                        result = ProcessCart(response, parameters);
                        result.resultset.Cart.Coupons.Add(new CouponCodeBase()
                        {
                            Code = theParams.Coupons[0].Code, Message = apiResponse.Model.message
                        });
                    }
                    else
                    {
                        _errors.Add(new SiteError {
                            Message = new ErrorMessage(apiResponse.Model.message, Config.Constants.GenericError)
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                _errors.Add(ex.Handle("CheckoutBillingCoupon.GetResponse", ErrorSeverity.FollowUp, ErrorType.RequestError));
            }
            return(result);
        }
Ejemplo n.º 2
0
        private IResponseBase GetResponse(DWClientConfig config)
        {
            var result = new Response <StoreLocatorResponse>();

            try
            {
                var apiResponse = DWClient.GetAPIResponse <StoreResult>(config);

                if (apiResponse.ResponseStatus.Code == HttpStatusCode.OK)
                {
                    result.resultset = new StoreLocatorResponse(apiResponse.Model);
                }
                else
                {
                    _errors.Add(new SiteError
                    {
                        Message =
                            new ErrorMessage(Config.Constants.GenericError,
                                             apiResponse.ResponseStatus.Message.ToString())
                    });
                }
            }
            catch (Exception ex)
            {
                _errors.Add(ex.Handle("StoreLocator.GetResponse", ErrorSeverity.FollowUp, ErrorType.RequestError));
            }
            return(result);
        }
Ejemplo n.º 3
0
        private Response <MenuResponse> GetResponse(DWClientConfig config)
        {
            var result = new Response <MenuResponse>();

            try
            {
                var dwCategoryDataCachekey = string.Format(Config.CacheKeys.DWCategoryData, config.Path);
                var apiResponse            = CacheMemory.Get <APIResponse <DemandWare.Models.DTOs.Category> >(dwCategoryDataCachekey);
                if (_isRoot && result.resultset.Menu.Count == 0)
                {
                    apiResponse = null;
                }
                if (apiResponse == null || apiResponse.Model == null)
                {
                    try
                    {
                        apiResponse = DWClient.GetAPIResponse <DemandWare.Models.DTOs.Category>(config);
                        if (apiResponse != null && apiResponse.ResponseStatus.Code == HttpStatusCode.OK && apiResponse._errors == null)
                        {
                            //CacheMemory.SetAndExpiresHoursAsync(dwCategoryDataCachekey, apiResponse, 4);
                            result.resultset = new MenuResponse(apiResponse.Model, _request.Path);
                            if (_isRoot || _request.KeepTraversing)
                            {
                                SetMenuItems(result);
                                if (_isRoot)
                                {
                                    Update_MenuBy_CmsAndFtpFile(result);
                                }
                            }
                        }
                        else
                        {
                            if (apiResponse != null)
                            {
                                _errors.Add(new SiteError
                                {
                                    Message = new ErrorMessage(Config.Constants.GenericError, apiResponse.ResponseStatus.Message)
                                });
                            }
                        }
                    }
                    catch (Exception) {}
                }
            }
            catch (Exception ex)
            {
                if (_isRoot)
                {
                    _errors.Add(ex.Handle("Menu.GetResponse", ErrorSeverity.FollowUp, ErrorType.RequestError));
                }
            }
            return(result);
        }
Ejemplo n.º 4
0
        private IResponseBase GetResponse(DWClientConfig config)
        {
            var result = new Response <ProductDetailExtensionResponse>();

            try
            {
                APIResponse apiResponse = null;
                if (_hasMultipleProducts)
                {
                    apiResponse = DWClient.GetAPIResponse <ProductResult>(config);
                }
                else
                {
                    apiResponse = DWClient.GetAPIResponse <DWProduct>(config);
                }

                if (apiResponse.ResponseStatus.Code == HttpStatusCode.OK)
                {
                    if (_hasMultipleProducts)
                    {
                        result.resultset = new ProductDetailExtensionResponse(((APIResponse <ProductResult>)apiResponse).Model, apiResponse.Raw);
                    }
                    else
                    {
                        result.resultset = new ProductDetailExtensionResponse(ProductDetailExtensionResponse.GetProductResult(((APIResponse <DWProduct>)apiResponse).Model));
                    }
                    result.template = Config.ResponseTemplates.ProductDetailExtension;
                }
                else
                {
                    _errors.Add(new SiteError
                    {
                        Message = new ErrorMessage(Config.Constants.GenericError, apiResponse.ResponseStatus.Message)
                    });
                }
            }
            catch (Exception ex)
            {
                _errors.Add(ex.Handle("ProductDetailExtension.GetResponse", ErrorSeverity.FollowUp,
                                      ErrorType.RequestError));
            }
            return(result);
        }
Ejemplo n.º 5
0
        private DWClientConfig BuildAPIConfig(IRequestParameter parameters)
        {
            var clientConfig = new DWClientConfig(_core);
            var path         = string.Format("{0}/{1}", Config.DWPath.ProductDetail, _request.Id);

            try
            {
                var sb = new StringBuilder();
                sb.Append("expand=options,images,prices,variations,availability,promotions");
                //Per OCAPI 17.2 - Added all_images=true to Display Image_Groups
                sb.Append("&all_images=true");
                clientConfig.Path   = path;
                clientConfig.Query  = sb.ToString();
                clientConfig.Method = HttpMethod.GET;
                return(clientConfig);
            }
            catch (Exception ex)
            {
                _errors.Add(ex.Handle(string.Format("Product.BuildAPIConfig ({0})", path), ErrorSeverity.FollowUp, ErrorType.RequestError));
                return(clientConfig);
            }
        }
Ejemplo n.º 6
0
        private IResponseBase GetResponse(DWClientConfig config)
        {
            var result = new Response <ProductListExtensionResponse>();

            try
            {
                APIResponse apiResponse = null;
                if (_hasMultipleProducts)
                {
                    apiResponse = DWClient.GetAPIResponse <ProductResult>(config);
                }
                else
                {
                    apiResponse = DWClient.GetAPIResponse <DWProduct>(config);
                }

                if (apiResponse.ResponseStatus.Code == HttpStatusCode.OK)
                {
                    if (_hasMultipleProducts)
                    {
                        var productResult = ((APIResponse <ProductResult>)apiResponse).Model;
                        productResult.Products = SetProductBrands(productResult.Products, apiResponse.Raw);
                        result.resultset       = new ProductListExtensionResponse(productResult, _request.Colors, apiResponse.Raw);
                    }
                    else
                    {
                        var product = ((APIResponse <DWProduct>)apiResponse).Model;
                        if (_usePredefinedVariations)
                        {
                            ReplaceColors(product);
                        }

                        result.resultset = new ProductListExtensionResponse(ProductListExtensionResponse.GetProductResult(product), _request.Colors, apiResponse.Raw);
                    }

                    result.template = Config.ResponseTemplates.ProductListExtension;
                    foreach (var productItem in result.resultset.ProductIdToExtension)
                    {
                        try
                        {
                            var productsnapshot = PowerReviewHelper.GetSnapshot(productItem.Key);
                            productItem.Value.Rating = (productsnapshot.average_rating == null)? 0: decimal.Parse((productsnapshot.average_rating));
                        }
                        catch (Exception ex)
                        {
                            productItem.Value.Rating = 0;
                        }
                    }
                }
                else
                {
                    _errors.Add(new SiteError {
                        Message = new ErrorMessage(Config.Constants.GenericError, apiResponse.ResponseStatus.Message.ToString())
                    });
                }
            }
            catch (Exception ex)
            {
                _errors.Add(ex.Handle("ProductListExtension.GetResponse", ErrorSeverity.FollowUp, ErrorType.RequestError));
            }

            return(result);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        private Response <SearchResponse> GetResponse(DWClientConfig config)
        {
            var result = new Response <SearchResponse>();

            try
            {
                var apiResponse = DWClient.GetAPIResponse <ProductSearchResult>(config);
                if (apiResponse.ResponseStatus.Code == HttpStatusCode.OK)
                {
                    result.resultset = new SearchResponse(apiResponse.Model, _request, _hrefLookup, _core);
                    result.template  = Config.ResponseTemplates.ProductList;
                    if (!string.IsNullOrEmpty(result.resultset.ProductIds))
                    {
                        PowerReviews = GetPwAvgRate(result.resultset.ProductIds);
                        var colors       = new List <string>();
                        var colorsFilter = result.resultset.Filters.AppliedFilterSections.Find(x => x.Note == "c_color");
                        if (colorsFilter != null)
                        {
                            colorsFilter.FilterOptions.ForEach(
                                option => colors.Add(option.Value.ToLowerInvariant().Replace("/", "_").Replace(" ", "")));
                        }
                        var productListExtension        = new ProductListExtension(_core, _errors);
                        var productListExtensionRequest = new ProductListExtensionRequest
                        {
                            ProductsIds = result.resultset.ProductIds,
                            Colors      = colors,
                            Products    = result.resultset.Products
                        };
                        productListExtension._usePredefinedVariations = !IsViewAllProductSearch;
                        var productListExtensionResponse = productListExtension.Execute(productListExtensionRequest);
                        var productIdToExtension         =
                            ((Response <ProductListExtensionResponse>)productListExtensionResponse).resultset
                            .ProductIdToExtension;
                        if (productIdToExtension.Any())
                        {
                            result.resultset.Products.ForEach(p =>
                            {
                                if (!productIdToExtension.ContainsKey(p.ProductId))
                                {
                                    return;
                                }
                                var extension = productIdToExtension[p.ProductId];
                                if (extension == null)
                                {
                                    return;
                                }
                                var avgRate = GetPowerRewiewAverageRateById(p.ProductId);
                                if (avgRate > 0)
                                {
                                    extension.Rating = avgRate;
                                }
                                if (string.IsNullOrEmpty(p.Image.Src) || colors.Count > 0)
                                {
                                    p.Image = extension.Image;
                                }
                                p.Description = extension.Brand;
                                p.Notes       = extension.ItemFeatures;
                                p.Rating      = extension.Rating;
                                p.IsAvailableInMultipleColors = extension.IsAvailableInMultipleColors;
                                p.AvailableVariations         = extension.AvailableVariations;
                                p.ProductFlags = Product.LookupCallouts(extension.ProductFlags);
                                p.CallOuts     = extension.Callout;
                            });
                        }
                    }
                }
                else
                {
                    _errors.Add(new SiteError
                    {
                        Message = new ErrorMessage(Config.Constants.GenericError, apiResponse.ResponseStatus.Message)
                    });
                }
            }
            catch (Exception ex)
            {
                _errors.Add(ex.Handle(string.Format("Search.GetResponse({0}):{1}-{2}", ex.LineNumber(), ex.Message, ex.StackTrace), ErrorSeverity.FollowUp, ErrorType.RequestError));
            }
            return(result);
        }