Ejemplo n.º 1
0
        public ActionResult SearchForm()
        {
            var model          = new ProductSearchViewModel();
            var formCollection = new FormCollection(Request.Form);

            TryUpdateModel(model, formCollection);

            var keywords = Request.QueryString["keywords"];

            if (!string.IsNullOrWhiteSpace(keywords))
            {
                model.Keywords = keywords;
            }

            var brands = Request.QueryString["brand"];

            if (!string.IsNullOrWhiteSpace(brands))
            {
                model.Brand = brands.Split(',').ToList();
            }

            var selectedColours = Request.QueryString["SelectedColours"];

            if (!string.IsNullOrWhiteSpace(selectedColours))
            {
                model.SelectedColours = selectedColours.Split(',').ToList();
            }

            if (formCollection.Has("PriceRange"))
            {
                var priceRange = formCollection["PriceRange"].Split(',').Select(x => x.AsDecimal(0)).ToArray();
                model.MinPrice = priceRange[0];
                model.MaxPrice = priceRange[1];
            }

            if (formCollection.Has("Martindale"))
            {
                model.Martindale = formCollection["Martindale"].AsInt(0);
            }

            model.ProductCategories = _productCategoriesService.GetAll().ToList();
            model.Options           = _skuAttributeOptionsService.GetAll().ToList();

            if (B2BCheckoutService.IsB2BUserLoggedIn(HttpContext))
            {
                model.IsMartindaleFilterVisible     = true;
                model.IsEndUseFilterVisible         = true;
                model.IsTypeFilterVisible           = true;
                model.IsFlameRetardantFilterVisible = true;
            }

            return(PartialView(model));
        }
Ejemplo n.º 2
0
        public override ActionResult Search(FormCollection formCollection)
        {
            var productModel = new ProductSearchViewModel();

            TryUpdateModel <ProductSearchViewModel>(productModel, formCollection);

            if (formCollection.Has("PriceRange"))
            {
                var priceRange = formCollection["PriceRange"].Split(',').Select(x => x.AsDecimal(0)).ToArray();
                productModel.MinPrice = priceRange[0];
                productModel.MaxPrice = priceRange[1];
            }

            if (formCollection.Has("Martindale"))
            {
                productModel.Martindale = formCollection["Martindale"].AsInt(0);
            }

            var searchCriteria = new SearchCriteria
            {
                OrderBy        = productModel.OrderBy ?? "default",
                ResultsPerPage = productModel.ResultsPerPage,
                CurrentPage    = productModel.CurrentPage
            };

            searchCriteria.CustomCriteria.Add("CurrencyId", CommerceContext.Currency.CurrentForPricing.Id.ToString());
            searchCriteria.CustomCriteria.Add("ShopId", CommerceContext.Shop.CurrentShop.Id.ToString());
            searchCriteria.CustomCriteria.Add("MinPrice", productModel.MinPrice);
            searchCriteria.CustomCriteria.Add("MaxPrice", productModel.MaxPrice);
            searchCriteria.CustomCriteria.Add("ProductCategoryID", productModel.ProductCategory.ToDelimitedString());
            searchCriteria.CustomCriteria.Add("Martindate", productModel.Martindale);

            var attributeOptions = ToAttributeString(productModel.Brand,
                                                     productModel.Patterns,
                                                     productModel.Type,
                                                     productModel.FlameRetardant,
                                                     productModel.EndUse);

            searchCriteria.CustomCriteria.Add("Attributes", attributeOptions);
            searchCriteria.CustomCriteria.Add("Colours", productModel.SelectedColours);

            var results = _skuProductsService.ProductCatalogue.Products.PerformSearch(searchCriteria).Cast <ProductSearchResult>();

            if (Request.IsJsonRequest())
            {
                return(Json(results));
            }

            return(PartialView(results));
        }
Ejemplo n.º 3
0
        public ActionResult AjaxSearch(FormCollection formCollection = null)
        {
            var productSearchViewModel = new ProductSearchViewModel();

            if (formCollection != null)
            {
                if (!string.IsNullOrEmpty(formCollection["keywords"]))
                {
                    formCollection["keywords"] = formCollection["keywords"].Replace(",", " ");
                }
                TryUpdateModel(productSearchViewModel, formCollection);
            }
            if (string.IsNullOrEmpty(productSearchViewModel.SortBy))
            {
                productSearchViewModel.SortBy = "default"; // "alphaasc";
            }
            //   if (productSearchViewModel.SortBy.ToLower() == "default")
            //   {
            //       productSearchViewModel.SortBy = "alphaasc";
            //   }
            var keywords = Request.QueryString["keywords"];

            if (!string.IsNullOrWhiteSpace(keywords))
            {
                productSearchViewModel.Keywords = keywords;
            }

            if (formCollection != null)
            {
                if (formCollection.Has("PriceRange"))
                {
                    var priceRange = formCollection["PriceRange"].Split(',').Select(x => x.AsDecimal(0)).ToArray();
                    productSearchViewModel.MinPrice = priceRange[0];
                    productSearchViewModel.MaxPrice = priceRange[1];
                }
            }
            productSearchViewModel.IsB2B = B2BCheckoutService.IsB2BUserLoggedIn(HttpContext);

            var searchCriteria = GetSearchCriteria(productSearchViewModel);

            if (!searchCriteria.CustomCriteria.Any(t => t.Key != "CurrencyId" && t.Key != "ShopId") &&
                !searchCriteria.DiscreteTerms.Any())
            {
                return(PartialView("Search", productSearchViewModel));
            }


            if (formCollection != null)
            {
                var brands = formCollection["brand"];
                if (!string.IsNullOrWhiteSpace(brands))
                {
                    productSearchViewModel.SelectedBrands = brands.Split(',').ToList();
                }
            }

            var CelebrosSiteKey   = ConfigurationManager.AppSettings["CelebrosSiteKey"];
            var CelebrosSearchURL = ConfigurationManager.AppSettings["CelebrosSearchURL"];

            var currentSiteId = CommerceContext.ColonyContext.CurrentSite.Id.ToString(); //CommerceContext.Shop.CurrentShop.Id.ToString();

            var results = _skuProductsService.ProductCatalogue.Products.PerformAjaxCelebrosSearch(searchCriteria, CelebrosSiteKey, CelebrosSearchURL, currentSiteId);

            if (results.SearchResults.Count == 0 && searchCriteria.CurrentPage == 1)
            {
                productSearchViewModel.NoResults = true;
            }
            productSearchViewModel.TotalResultCount     = results.SearchResults.RecordCount;
            productSearchViewModel.ProductSearchResults = results.SearchResults.Select(t =>
            {
                if (t.Images.Any())
                {
                    var featuredImage = t.Images.OrderBy(i => i.Order).First();

                    t.ImageUri           = Url.ImageUrl(featuredImage.ImageAssetID, "productcatalogue", "productthumbnail");
                    t.DetailImageUri     = Url.ImageUrl(featuredImage.ImageAssetID, "ProductCatalogue", "ProductDetail");
                    t.ImageAssetId       = featuredImage.ImageAssetID;
                    t.DetailImageAssetId = featuredImage.ImageAssetID;
                }
                return(t);
            }).ToList();

            //   productSearchViewModel.ProductCategories = results.AvailableProductCategories.Distinct().ToList();
            //   productSearchViewModel.Attributes = _skuAttributeService.GetAll().Distinct().ToList();
            productSearchViewModel.CurrentPage = searchCriteria.CurrentPage;

            productSearchViewModel.AttributeOptionCounts = results.AvailableSkuAttributeOptionIds
                                                           .GroupBy(t => t)
                                                           .Select(grouping => new { grouping.Key, Count = grouping.LongCount() })
                                                           .ToDictionary(t => t.Key.ToString(CultureInfo.InvariantCulture), t => t.Count);

            productSearchViewModel.Options                 = _skuAttributeOptionsService.GetForShop(CommerceContext.Shop.CurrentShop.Id).Distinct().ToList();
            productSearchViewModel.SearchHandle            = results.SearchHandle;
            productSearchViewModel.SearchTerms             = results.SearchSequence;
            productSearchViewModel.CelebrosOptions         = results.FilterOptions;
            productSearchViewModel.CelebrosLogHandle       = results.CelebrosLogHandle;
            productSearchViewModel.CelebrosSearchSessionId = results.CelebrosSearchSessionId;
            productSearchViewModel.LastPage                = results.LastPage;

            if (!string.IsNullOrEmpty(results.CelebrosCustomMessage))
            {
                productSearchViewModel.CelebrosCustomMessage = "<div class=\"searchBanner bedlinenBanner\">" + results.CelebrosCustomMessage + "</div>";
            }
            else
            {
                productSearchViewModel.CelebrosCustomMessage = "";
            }

            productSearchViewModel.IsProductCategoryFilterVisible = true;
            productSearchViewModel.IsPatternsFilterVisible        = true;
            //productSearchViewModel.IsDimOutFilterVisible = true;
            productSearchViewModel.IsProductGroupFilterVisible = true;
            productSearchViewModel.IsCompositionFilterVisible  = true;
            if (CommerceContext.Shop.CurrentShop.Id == 25)
            {
                productSearchViewModel.IsUsageFilterVisible         = false;
                productSearchViewModel.IsContractUsageFilterVisible = true;
            }
            else
            {
                productSearchViewModel.IsUsageFilterVisible         = true;
                productSearchViewModel.IsContractUsageFilterVisible = false;
            }

            productSearchViewModel.IsFabricTypesVisible          = false;
            productSearchViewModel.IsTrimmingTypesVisible        = true;
            productSearchViewModel.IsWallpaperTypesVisible       = false;
            productSearchViewModel.IsMartindaleFilterVisible     = true;
            productSearchViewModel.IsEndUseFilterVisible         = true;
            productSearchViewModel.IsTypeFilterVisible           = true;
            productSearchViewModel.IsFlameRetardantFilterVisible = true;
            productSearchViewModel.IsBrandFilterVisible          = true;
            productSearchViewModel.IsFRInherentVisible           = true;
            productSearchViewModel.IsFRTreatableVisible          = true;
            productSearchViewModel.isFRTreatedVisible            = true;

            if (productSearchViewModel.ProductSearchResults.All(t => t.Attributes.GetValueOrNull("Martindale") == null))
            {
                productSearchViewModel.IsMartindaleFilterVisible = false;
            }

            var cushionsearch = false;
            var othersearch   = false;

            foreach (var group in productSearchViewModel.SelectedProductGroups)
            {
                if (group == "6508" || group == "144")
                {
                    cushionsearch = true;
                }
                else
                {
                    if (group != "0")
                    {
                        othersearch = true;
                    }
                }
            }
            if (cushionsearch && !othersearch)
            {
                productSearchViewModel.IsFRInherentVisible  = false;
                productSearchViewModel.IsFRTreatableVisible = false;
                productSearchViewModel.isFRTreatedVisible   = false;
            }

            foreach (var group in productSearchViewModel.SelectedProductGroups.Where(group => group == "2981"))
            {
                productSearchViewModel.IsFabricTypesVisible = true;
            }

            foreach (var group in productSearchViewModel.SelectedProductGroups.Where(group => group == "2982"))
            {
                productSearchViewModel.IsWallpaperTypesVisible = true;
            }

            foreach (var group in productSearchViewModel.SelectedProductGroups.Where(group => group == "2980"))
            {
                productSearchViewModel.IsTrimmingTypesVisible = true;
            }

            if (productSearchViewModel.SelectedProductGroups.Count == 0 ||
                productSearchViewModel.SelectedProductGroups.FirstOrDefault() == string.Empty)
            {
                productSearchViewModel.IsFabricTypesVisible    = true;
                productSearchViewModel.IsTrimmingTypesVisible  = true;
                productSearchViewModel.IsWallpaperTypesVisible = true;
            }

            return(Json(productSearchViewModel, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 4
0
        public override ActionResult Search(FormCollection formCollection = null)
        {
            Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
            Response.Cache.SetCacheability(HttpCacheability.Public);
            Response.Cache.SetValidUntilExpires(false);
            Response.Cache.VaryByParams["*"] = true;

            var productSearchViewModel = new ProductSearchViewModel();

            productSearchViewModel.IsAjax = Request.IsAjaxRequest();

            if (formCollection != null)
            {
                TryUpdateModel(productSearchViewModel, formCollection);
            }
            else
            {
                List <string> URLParts = Request.Url.LocalPath
                                         .Split('/')
                                         .Where(x => !string.IsNullOrEmpty(x) && x.ToLower() != "search")
                                         .ToList();
                //if (URLParts.Length > 0) {
                foreach (var URLPart in URLParts)
                {
                    var option = LookupCelebrosOption(URLPart.ToLower());
                    if (option.Count > 0)
                    {
                        switch (option[0].Filter.ToLower())
                        {
                        case "selectedproductgroups":
                            productSearchViewModel.SelectedProductGroups.Add(option[0].CelebrosId.ToString());
                            break;

                        case "selectedcolours":
                            productSearchViewModel.SelectedColours.Add(option[0].CelebrosId.ToString());
                            break;

                        case "brand":
                        case "brands":
                            productSearchViewModel.SelectedBrands.Add(option[0].CelebrosId.ToString());
                            break;

                        case "selectedrooms":
                            productSearchViewModel.SelectedRooms.Add(option[0].CelebrosId.ToString());
                            break;

                        case "selectedpatterns":
                            productSearchViewModel.SelectedPatterns.Add(option[0].CelebrosId.ToString());
                            break;

                        case "selectedusage":
                            productSearchViewModel.SelectedUsage.Add(option[0].CelebrosId.ToString());
                            break;

                        case "selectedtrimmingtypes":
                            productSearchViewModel.SelectedTrimmingTypes.Add(option[0].CelebrosId.ToString());
                            break;
                        }
                    }
                    else
                    {
                        //free text search
                        productSearchViewModel.Keywords += URLPart.Replace('-', ' ');
                    }
                }
                //}
            }

            var keywords = Request.QueryString["keywords"];

            if (!string.IsNullOrWhiteSpace(keywords))
            {
                productSearchViewModel.Keywords = keywords;
            }

            if (formCollection != null)
            {
                if (formCollection.Has("PriceRange"))
                {
                    var priceRange = formCollection["PriceRange"].Split(',').Select(x => x.AsDecimal(0)).ToArray();
                    productSearchViewModel.MinPrice = priceRange[0];
                    productSearchViewModel.MaxPrice = priceRange[1];
                }
            }

            var searchCriteria = GetSearchCriteria(productSearchViewModel);

            if (searchCriteria.CustomCriteria.Where(t => t.Key != "CurrencyId" && t.Key != "ShopId").Count() == 0 &&
                searchCriteria.DiscreteTerms.Count() == 0)
            {
                return(PartialView("Search", productSearchViewModel));
            }

            if (B2BCheckoutService.IsB2BUserLoggedIn(HttpContext))
            {
                productSearchViewModel.IsMartindaleFilterVisible     = true;
                productSearchViewModel.IsEndUseFilterVisible         = true;
                productSearchViewModel.IsTypeFilterVisible           = true;
                productSearchViewModel.IsFlameRetardantFilterVisible = true;
            }

            return(PartialView("Search", productSearchViewModel));
        }