public void ContributeToQuery(Api.Model.Query query) { if (ViewSize != null) { query.ViewSize = ViewSize; } }
/// <summary> /// Handle search category page where the search results are presented /// </summary> /// <param name="searchPhrase"></param> /// <param name="categoryUrl"></param> /// <returns></returns> public ActionResult SearchCategoryPage(string searchPhrase, string categoryUrl) { Log.Info("Entering search page controller with search phrase: " + searchPhrase + ", category: " + categoryUrl); // Get facets // var facets = GetFacetParametersFromRequest(); PageModel templatePage = null; // Build query // Api.Model.Query query; if (categoryUrl != null) { var category = ECommerceContext.Client.CategoryService.GetCategoryByPath(categoryUrl); if (category != null) { query = new Api.Model.Query { SearchPhrase = searchPhrase, Category = category, Facets = facets, StartIndex = GetStartIndex() }; ECommerceContext.Set(ECommerceContext.CATEGORY, category); } else { return(NotFound()); } } else { query = new Api.Model.Query { SearchPhrase = searchPhrase, Facets = facets, StartIndex = GetStartIndex() }; } templatePage = this.ResolveTemplatePage(this.GetSearchPath()); // templatePage.Title = ?? TODO: What title to use for search results? SetupViewData(templatePage); this.GetQueryContributions(templatePage, query); var searchResult = ECommerceContext.Client.QueryService.Query(query); if (searchResult.RedirectLocation != null) { return(Redirect(ECommerceContext.LinkResolver.GetLocationLink(searchResult.RedirectLocation))); } ECommerceContext.Set(ECommerceContext.CURRENT_QUERY, query); ECommerceContext.Set(ECommerceContext.QUERY_RESULT, searchResult); ECommerceContext.Set(ECommerceContext.SEARCH_PHRASE, searchPhrase); ECommerceContext.Set(ECommerceContext.URL_PREFIX, ECommerceContext.LocalizePath("/search/") + searchPhrase); ECommerceContext.Set(ECommerceContext.FACETS, facets); ECommerceContext.Set(ECommerceContext.ROOT_TITLE, "Search Results"); // TODO: Have this configurable in locale properties so it can be translated return(View(templatePage)); }
/// <summary> /// Promotions /// </summary> /// <param name="entity"></param> /// <param name="containerSize"></param> /// <returns></returns> public ActionResult Promotions(EntityModel entity, int containerSize = 0) { SetupViewData(entity, containerSize); PromotionsWidget widget = (PromotionsWidget)entity; // Get promotions // IProductQueryResult queryResult = null; if (widget.CategoryReference != null) { var query = new Api.Model.Query(); var category = ResolveCategory(widget.CategoryReference); query.Category = category; if (widget.ViewType != null) { query.ViewType = (Api.Model.ViewType)Enum.Parse(typeof(Api.Model.ViewType), widget.ViewType.ToUpper()); } queryResult = ECommerceContext.Client.QueryService.Query(query); } else { // Use category from page controller // queryResult = (IProductQueryResult)ECommerceContext.Get(ECommerceContext.QUERY_RESULT); } if (queryResult == null) { queryResult = GetResultFromPageTemplate(); } if (queryResult != null) { widget.Promotions = queryResult.Promotions.ToList(); } else { var product = (IProduct)ECommerceContext.Get(ECommerceContext.PRODUCT); if (product != null) { widget.Promotions = product.Promotions; } else { widget.Promotions = Enumerable.Empty <IPromotion>().ToList(); } } return(View(entity.MvcData.ViewName, entity)); }
/// <summary> /// Go through all entities on the page (excluding header & footer) and check for contributions to the E-Commerce query (such as view size, filter attributes etc). /// </summary> /// <param name="templatePage"></param> /// <param name="query"></param> protected void GetQueryContributions(PageModel templatePage, Api.Model.Query query) { foreach (var region in templatePage.Regions) { if (!region.Name.Equals("Header") && !region.Name.Equals("Footer")) { foreach (EntityModel entity in region.Entities) { if (entity is IQueryContributor) { ((IQueryContributor)entity).ContributeToQuery(query); } } } } }
protected IProductQueryResult GetResultFromPageTemplate() { String requestPath = HttpContext.Request.Path; if (requestPath.StartsWith(ECommerceContext.LocalizePath("/categories"))) { var category = this.GetCategoryFromPageTemplate(requestPath); var query = new Api.Model.Query { Category = category, Facets = ECommerceContext.Get(ECommerceContext.FACETS) as IList <FacetParameter> }; return(ECommerceContext.Client.QueryService.Query(query)); } return(null); }
public ActionResult CategoryPage(string categoryUrl) { Log.Info("Entering category page controller with URL: " + categoryUrl); if (String.IsNullOrEmpty(categoryUrl)) { categoryUrl = "/"; } // Get facets // var facets = GetFacetParametersFromRequest(); PageModel templatePage = null; var category = ECommerceContext.Client.CategoryService.GetCategoryByPath(categoryUrl); if (category != null) { templatePage = this.ResolveTemplatePage(this.GetSearchPath(categoryUrl, category)); templatePage.Title = category.Name; SetupViewData(templatePage); var query = new Api.Model.Query { Category = category, Facets = facets, StartIndex = GetStartIndex() }; this.GetQueryContributions(templatePage, query); var searchResult = ECommerceContext.Client.QueryService.Query(query); if (searchResult.RedirectLocation != null) { return(Redirect(ECommerceContext.LinkResolver.GetLocationLink(searchResult.RedirectLocation))); } ECommerceContext.Set(ECommerceContext.CURRENT_QUERY, query); ECommerceContext.Set(ECommerceContext.QUERY_RESULT, searchResult); ECommerceContext.Set(ECommerceContext.URL_PREFIX, ECommerceContext.LocalizePath("/c")); ECommerceContext.Set(ECommerceContext.FACETS, facets); ECommerceContext.Set(ECommerceContext.CATEGORY, category); } else { Log.Warn("Category page with URL: /" + categoryUrl + " does not exists."); return(NotFound()); } return(View(templatePage)); }