public ActionResult Search(string s, int? page, int? pageSize) { if (s.IsNullOrTrimmedEmpty()) { return View("NoProductFound"); } var pageId = GetPageId(page); s = s.Trim(); s = Noises.Clean("fr", s); int count = 0; pageSize = pageSize.GetValueOrDefault(ERPStoreApplication.WebSiteSettings.Catalog.PageSize); var parameters = CatalogService.RemoveNotFilteredParameters(Request.Url.Query.ToHtmlDecodedNameValueDictionary()); var category = CatalogService.GetCategoryByCode(Request["category"]); var brand = CatalogService.GetBrandByName(Request["brand"]); var filter = CatalogService.CreateProductListFilter(HttpContext); filter.ExtendedParameters = parameters; filter.Search = s; if (category != null) { filter.ProductCategoryId = category.Id; } if (brand != null) { filter.BrandId = brand.Id; } var productList = CatalogService.GetProductListBySearch(filter, pageId, pageSize.Value, out count); if (pageId == 0) { EventPublisherService.Publish(new Models.Events.ProductSearchEvent(User.GetUserPrincipal(), s, count, CatalogService.Name)); ViewData["search"] = filter.Search; ViewData["resultCount"] = count; } if (productList == null || productList.Count == 0) { return View("NoProductFound"); } // Afficher directement la fiche produit if (productList.Count == 1) { var p = productList.First(); var urlHelper = new UrlHelper(this.ControllerContext.RequestContext); var url = urlHelper.Href(p); return Redirect(url); } // Recherche des tarifs client si celui-ci est connecté CatalogService.ApplyBestPrice(productList, User.GetUserPrincipal().CurrentUser); var result = new Models.ProductList(productList); result.Query = s; result.ItemCount = count; result.PageIndex = pageId + 1; result.PageSize = pageSize.Value; result.ExtendedParameters = parameters; result.Category = category; result.Brand = brand; result.ListType = ERPStore.Models.ProductListType.Search; ViewData.Model = result; return View("ProductSearchResult"); }
public ActionResult Category(string link, int? page, int? pageSize) { if (link != null) { link = link.Trim().TrimEnd('/'); } else { // return RedirectToAction("CategoryList"); return RedirectToERPStoreRoute(ERPStoreRoutes.PRODUCT_CATEGORIES); } var category = CatalogService.GetCategoryByLink(link); if (category == null) { // Recherche dans la liste de compensation string fileName = Server.MapPath(@"/app_data/categories-compensation.txt"); var categoryCompensationListFileInfo = new System.IO.FileInfo(fileName); if (!categoryCompensationListFileInfo.Exists) { Logger.Notification("Missing category : {0} on {1}", link, fileName); return new RedirectResult("/"); } using (var content = categoryCompensationListFileInfo.OpenText()) { while(true) { var line = content.ReadLine(); if (line.IsNullOrTrimmedEmpty()) { break; } string[] compensation = line.Split(':'); var badlink = compensation[0]; if (badlink.Equals(link, StringComparison.InvariantCultureIgnoreCase)) { category = CatalogService.GetCategoryByLink(compensation[1]); if (category != null) { break; } } } } if (category == null) { var adminUrl = string.Format("http://{0}/admin/ProductCategoryUrlMovedPermanently?badUrl={1}", ERPStoreApplication.WebSiteSettings.CurrentUrl, link); Logger.Notification("Missing category : {0}\r\n {1}", link, adminUrl); return new RedirectResult("/"); } else { var urlHelper = new UrlHelper(this.ControllerContext.RequestContext); var redirect = urlHelper.Href(category); MovedPermanently(redirect); } } if (!page.HasValue || page < 0) { page = 0; } else { page = page.Value - 1; } if (page < 0) { page = 0; } int count = 0; pageSize = pageSize.GetValueOrDefault(ERPStoreApplication.WebSiteSettings.Catalog.PageSize); var parameters = CatalogService.RemoveNotFilteredParameters(Request.Url.Query.ToHtmlDecodedNameValueDictionary()); var brand = CatalogService.GetBrandByName(Request["brand"]); var productSearch = CatalogService.CreateProductListFilter(this.HttpContext); if (brand != null) { productSearch.BrandId = brand.Id; } productSearch.ProductCategoryId = category.Id; productSearch.ExtendedParameters = parameters; var productList = CatalogService.GetProductListBySearch(productSearch, page.Value, pageSize.Value, out count); // Recherche des tarifs client si celui-ci est connecté CatalogService.ApplyBestPrice(productList, User.GetUserPrincipal().CurrentUser); var pageIndex = page.Value + 1; var result = new Models.ProductList(productList); result.Category = category; result.ItemCount = count; result.PageIndex = pageIndex; result.PageSize = pageSize.Value; result.ExtendedParameters = parameters; result.ListType = ERPStore.Models.ProductListType.Category; result.Brand = brand; ViewData.Model = result; return View(); }