Esempio n. 1
0
        public IResponseBase Execute(IRequestParameter parameters)
        {
            var result = new Response <SearchResponse>();

            _request = (SearchRequest)parameters;

            try
            {
                if (_request.Href != null)
                {
                    var cacheKey = string.Format(Config.CacheKeys.Search, _request.Href, _request.Page, _request.PageSize);
                    IsViewAllProductSearch = _request.Href.Contains("view-all");
                    IsEmailCamPaign        = _request.Href.ToLower().Contains("utm_medium=email");
                    result = CacheMemory.Get <Response <SearchResponse> >(cacheKey);
                    if (result.resultset != null && string.IsNullOrWhiteSpace(result.resultset.Href))
                    {
                        _hrefLookup = HrefLookup.Load(_core);
                        var config = BuildAPIConfig(parameters);

                        if (config != null)
                        {
                            result = GetResponse(config);
                        }

                        if (result.resultset.Filters != null && result.resultset.Filters.FilterSections != null)
                        {
                            result.resultset.Filters.FilterSections = SelectSpecifiedSize(result.resultset.Filters.FilterSections);
                        }

                        var href = ParsingHelper.GetHrefWithoutQueryString(_request.Href);
                        result.resultset.CategoryID = _hrefLookup.Forward.Get(href);
                        var resultVideos = CacheMemory.Get <Dictionary <string, PaylessMadCms.PromoSlot> >(Config.CacheKeys.CmsVideos);
                        if (resultVideos != null && resultVideos.Keys.Contains(href))
                        {
                            result.resultset.Promo = resultVideos[href];
                        }

                        if (!_errors.Any() && result.resultset.Products.Any())
                        {
                            CacheMemory.SetAndExpiresMinutesAsync(cacheKey, result, 15);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _errors.Add(ex.Handle(string.Format("Search.Execute({0}):{1}-{2}", ex.LineNumber(), ex.Message, ex.StackTrace), ErrorSeverity.FollowUp, ErrorType.RequestError));
            }
            return(result);
        }
Esempio n. 2
0
 private void Update_MenuBy_CmsAndFtpFile(Response <MenuResponse> result)
 {
     try
     {
         var madDash = new PaylessMadCms(_core);
         var categoryImagesLookup = madDash.CategoryImages();
         var hrefLookup           = HrefLookup.Load(_core);
         if (_errors.Any() || !result.resultset.Menu.Any())
         {
             return;
         }
         Update_MenuHrefLookup(result.resultset.Menu, categoryImagesLookup, hrefLookup);
         Add_MenuItem_GiftCard(result);
         Add_MenuItem_Help(result);
     }
     catch (Exception ex)
     {
         _errors.Add(ex.Handle("Menu.Update_MenuBy_CmsAndFtpFile", ErrorSeverity.FollowUp, ErrorType.RequestError));
     }
 }
Esempio n. 3
0
        public IResponseBase Execute(IRequestParameter parameters)
        {
            var result = new Response <CategoryResponse>();

            try
            {
                _request = (CategoryRequest)parameters;
                var hrefLookup = HrefLookup.Load(_core);
                var catid      = hrefLookup.Forward.Get(ParsingHelper.GetHrefWithoutQueryString(_request.Href));
                var cacheKey   = string.Format(Config.CacheKeys.Category, catid);

                result = CacheMemory.Get <Response <CategoryResponse> >(cacheKey);
                if (result == null || string.IsNullOrWhiteSpace(result.resultset.CategoryID))
                {
                    var forwardDate = GetDateFromRequest();
                    var maddash     = new PaylessMadCms(_core);
                    result.resultset = maddash.GetCategoryData(catid, forwardDate);
                    var config      = BuildAPIConfig(parameters, catid);
                    var apiResponse = DWClient.GetAPIResponse <ProductSearchResult>(config);
                    if (apiResponse.ResponseStatus.Code == HttpStatusCode.OK)
                    {
                        result.resultset.Filters = new ExtendedFilter(apiResponse.Model.Refinements, null, hrefLookup);
                    }

                    result.resultset.CategoryID = catid;
                    if (result.errors.Count == 0)
                    {
                        CacheMemory.SetAndExpiresHoursAsync(cacheKey, result, 1);
                    }
                }
            }
            catch (Exception ex)
            {
                _errors.Add(ex.Handle("Category.Execute", ErrorSeverity.FollowUp, ErrorType.RequestError));
            }
            return(result);
        }
Esempio n. 4
0
 private void Update_MenuHrefLookup(List <MenuItem> menu, NameValueCollection categoryImagesLookup, HrefLookup hrefLookup)
 {
     try
     {
         menu.ForEach(item =>
         {
             item.Image.Src = categoryImagesLookup.Get(item.CategoryId);
             item.Href      = hrefLookup.Reverse.Get(item.CategoryId) ?? "#";
             Update_MenuHrefLookup(item.Subs, categoryImagesLookup, hrefLookup);
         });
     }
     catch (Exception ex)
     {
         _errors.Add(ex.Handle("Menu.Update_MenuHrefLookup", ErrorSeverity.FollowUp, ErrorType.RequestError));
     }
 }
Esempio n. 5
0
        public SearchResponse(ProductSearchResult searchResult, SearchRequest request, HrefLookup hrefLookup, ICore core) : this()
        {
            _core = core;
            if (searchResult.Count > 0)
            {
                Filters = new ExtendedFilter(searchResult.Refinements, searchResult.SelectedRefinements, hrefLookup);
                Sorter  = new ExtendedSorter(searchResult.SortingOptions, searchResult.SelectedSortingOption);
                var catName = hrefLookup.Forward.Get(ParsingHelper.GetHrefWithoutQueryString(request.Href));
                var plpInfo = GetAdditionalPlpInfo(request, catName);
                foreach (var product in searchResult.Hits.Where(a => a.Price != Convert.ToDecimal(Config.Params.PriceToExclude)).ToList())
                {
                    Products.Add(new ProductListItem(product, GetExtraPLPInfo(plpInfo, product.ProductId), GetColorVariations(plpInfo, product.ProductId)));
                }

                Pager.PageSize     = request.PageSize;
                Pager.CurrentPage  = request.Page;
                Pager.RecordCount  = searchResult.Count;
                Pager.TotalRecords = searchResult.Total;
                Pager.TotalPages   = (int)Math.Ceiling((double)Pager.TotalRecords / Pager.PageSize);
                ProductIds         = string.Join(",", Products.Select(x => x.ProductId));
                Breadcrumbs        = string.Join(" | ", Filters.Path.Select(x => x.Key.ToLowerInvariant()));
            }
            else
            {
                Breadcrumbs = "We're sorry, no products were found for your search";
            }

            Term = searchResult.Query;
            Href = request.Href;
        }
Esempio n. 6
0
        private List <ProductSearchRefinementValue> DrillCategoryDown(List <ProductSearchRefinementValue> values, List <KeyValuePair <string, string> > path, string selectedCategory, HrefLookup hrefLookup)
        {
            var childWithValues = values.Where(x => x.Values.Any()).FirstOrDefault();

            if (childWithValues != null)
            {
                path.Add(new KeyValuePair <string, string>(childWithValues.Label.ToLowerInvariant(), hrefLookup.Reverse.Get(childWithValues.Value)));
                return(DrillCategoryDown(childWithValues.Values, path, selectedCategory, hrefLookup));
            }
            else
            {
                var selectedMatch = values.Where(x => x.Value.Equals(selectedCategory)).FirstOrDefault();
                if (selectedMatch != null)
                {
                    path.Add(new KeyValuePair <string, string>(selectedMatch.Label.ToLowerInvariant(), hrefLookup.Reverse.Get(selectedMatch.Value)));
                }
            }

            return(values);
        }
Esempio n. 7
0
        public ExtendedFilter(List <ProductSearchRefinement> refiners, Dictionary <string, string> selectedRefiners, HrefLookup hrefLookup) : this()
        {
            if (refiners != null)
            {
                // Find Category Refiner
                var selectedCategory = string.Empty;
                if (selectedRefiners != null)
                {
                    if (selectedRefiners.ContainsKey("cgid"))
                    {
                        selectedCategory = selectedRefiners["cgid"];
                    }
                }
                var categoryRefiner = refiners.Where(x => x.AttributeId.Equals("cgid")).FirstOrDefault() ?? new ProductSearchRefinement();

                // Create Path
                DrillCategoryDown(categoryRefiner.Values, Path, selectedCategory, hrefLookup);

                // Create Sub Menu Filter
                SubMenu = new MenuItem(categoryRefiner, Path);

                // Remove Non-Clickable Categories From Path
                Path.RemoveAll(x => x.Key == "featured" || x.Key == "styles");

                // Create Applied Filters
                if (selectedRefiners != null)
                {
                    foreach (var refiner in selectedRefiners)
                    {
                        AppliedFilterSections.Add(new ExtendedFilterGrouping(refiner));
                    }
                }

                // Create The Rest Of Filters
                foreach (var refiner in refiners)
                {
                    if (refiner.Values.Any() && !refiner.AttributeId.Equals("cgid"))
                    {
                        var selectedFilters = AppliedFilterSections.Find(x => refiner.AttributeId.EndsWith(x.Note));
                        FilterSections.Add(new ExtendedFilterGrouping(refiner, selectedFilters));

                        FilterSections.RemoveAll(section => section.FilterOptions.Count == 0);
                    }
                }
            }
        }