public async Task <CategoryBrowsingViewModel> GetCategoryAvailableProductsAsync(GetBrowseCategoryParam param) { if (param == null) { throw new ArgumentNullException(nameof(param)); } if (ViewModel != null) { return(ViewModel); } ViewModel = await CategoryBrowsingViewService.GetCategoryBrowsingViewModelAsync(new GetCategoryBrowsingViewModelParam { CategoryId = param.CategoryId, CategoryName = await GetCategoryNameAsync(param.CategoryId), BaseUrl = RequestUtils.GetBaseUrl(param.Request).ToString(), IsAllProducts = CategoryMetaContext.GetIsAllProductPage(), Page = param.Page, SortBy = param.SortBy, SortDirection = param.SortDirection, InventoryLocationIds = await InventoryLocationProvider.GetInventoryLocationIdsForSearchAsync(), SelectedFacets = SearchUrlProvider.BuildSelectedFacets(param.Request.QueryString).ToList(), CultureInfo = ComposerContext.CultureInfo, }).ConfigureAwait(false); return(ViewModel); }
public virtual async Task <IHttpActionResult> GetCategoryFacets(GetCategoryFacetsRequest request) { var param = new GetCategoryBrowsingViewModelParam { CategoryId = request.CategoryId, CategoryName = string.Empty, BaseUrl = RequestUtils.GetBaseUrl(Request).ToString(), IsAllProducts = false, NumberOfItemsPerPage = 0, Page = 1, SortBy = "score", SortDirection = "desc", InventoryLocationIds = await InventoryLocationProvider.GetInventoryLocationIdsForSearchAsync().ConfigureAwait(false), CultureInfo = ComposerContext.CultureInfo }; if (!string.IsNullOrEmpty(request.QueryString)) { var queryString = HttpUtility.ParseQueryString(request.QueryString); param.SelectedFacets = SearchUrlProvider.BuildSelectedFacets(queryString).ToList(); } var viewModel = await CategoryBrowsingViewService.GetCategoryBrowsingViewModelAsync(param).ConfigureAwait(false); viewModel.ProductSearchResults.Facets = viewModel.ProductSearchResults.Facets.Where(f => !f.FieldName.StartsWith(SearchConfiguration.CategoryFacetFiledNamePrefix)).ToList(); return(Ok(viewModel)); }
public virtual async Task <CategoryBrowsingViewModel> GetViewModelAsync() { if (_viewModel != null) { return(_viewModel); } var categoryId = CategoryMetaContext.GetCategoryId(); _viewModel = await CategoryBrowsingViewService.GetCategoryBrowsingViewModelAsync(new GetCategoryBrowsingViewModelParam { CategoryId = categoryId, CategoryName = await GetCategoryNameAsync(categoryId).ConfigureAwait(false), BaseUrl = RequestUtils.GetBaseUrl(Request).ToString(), IsAllProducts = CategoryMetaContext.GetIsAllProductPage(), NumberOfItemsPerPage = SearchConfiguration.MaxItemsPerPage, Page = CurrentPage, SortBy = SortBy, SortDirection = SortDirection, InventoryLocationIds = await InventoryLocationProvider.GetInventoryLocationIdsForSearchAsync().ConfigureAwait(false), SelectedFacets = SearchUrlProvider.BuildSelectedFacets(Request.QueryString).ToList(), CultureInfo = ComposerContext.CultureInfo, }).ConfigureAwait(false); return(_viewModel); }
protected virtual async Task <List <InventoryItemAvailabilityViewModel> > FindInventoryItemStatus(List <string> skus) { var inventoryItemsAvailabilityViewModel = await InventoryViewService.FindInventoryItemStatus(new FindInventoryItemStatusParam { CultureInfo = ComposerContext.CultureInfo, Scope = ComposerContext.Scope, Date = DateTime.UtcNow, Skus = skus, InventoryLocationId = await InventoryLocationProvider.GetDefaultInventoryLocationIdAsync() }); return(inventoryItemsAvailabilityViewModel); }
protected virtual async Task <IEnumerable <ProductIdentifier> > GetSameCategoryProductIdentifier(GetProductIdentifiersParam getProductIdentifiersParam, string categoryId) { if (getProductIdentifiersParam == null) { throw new ArgumentNullException(nameof(getProductIdentifiersParam)); } if (string.IsNullOrWhiteSpace(categoryId)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(), nameof(categoryId)); } var sameCategoryProductIdentifier = new List <ProductIdentifier>(); var productInSameCategoryParam = new GetProductsInSameCategoryParam() { CategoryId = categoryId, CultureInfo = getProductIdentifiersParam.CultureInfo, Scope = getProductIdentifiersParam.Scope, MaxItems = getProductIdentifiersParam.MaxItems, SortBy = "score", InventoryLocationIds = await InventoryLocationProvider.GetInventoryLocationIdsForSearchAsync(), CurrentProductId = getProductIdentifiersParam.ProductId, AvailabilityDate = FulfillmentContext.AvailabilityAndPriceDate }; var sameCategoryProducts = await RelationshipRepository.GetProductInSameCategoryAsync(productInSameCategoryParam).ConfigureAwait(false); if (sameCategoryProducts.Documents.Any()) { sameCategoryProductIdentifier = sameCategoryProducts.Documents.Select(d => { string variantId = null; if (d.PropertyBag.ContainsKey(VariantPropertyBagKey)) { variantId = d.PropertyBag[VariantPropertyBagKey] as string; } return(new ProductIdentifier { ProductId = d.ProductId, VariantId = variantId }); }).ToList(); } return(sameCategoryProductIdentifier); }
public virtual async Task <IHttpActionResult> GetSearchResults(GetSearchResultsRequest request) { var queryString = HttpUtility.ParseQueryString(request.QueryString ?? ""); var SelectedFacets = SearchUrlProvider.BuildSelectedFacets(queryString).ToList(); var CurrentPage = int.TryParse(queryString[SearchRequestParams.Page], out int page) && page > 0 ? page : 1; var SortDirection = queryString[SearchRequestParams.SortDirection] ?? SearchRequestParams.DefaultSortDirection; var SortBy = queryString[SearchRequestParams.SortBy] ?? SearchRequestParams.DefaultSortBy; var BaseUrl = RequestUtils.GetBaseUrl(Request).ToString(); var Keywords = queryString[SearchRequestParams.Keywords]; BaseSearchViewModel viewModel; if (!string.IsNullOrEmpty(request.CategoryId)) { var param = new GetCategoryBrowsingViewModelParam { CategoryId = request.CategoryId, CategoryName = string.Empty, BaseUrl = BaseUrl, IsAllProducts = false, NumberOfItemsPerPage = SearchConfiguration.MaxItemsPerPage, Page = CurrentPage, SortBy = SortBy, SortDirection = SortDirection, InventoryLocationIds = await InventoryLocationProvider.GetInventoryLocationIdsForSearchAsync().ConfigureAwait(false), SelectedFacets = SelectedFacets, CultureInfo = ComposerContext.CultureInfo, }; viewModel = await CategoryBrowsingViewService.GetCategoryBrowsingViewModelAsync(param).ConfigureAwait(false); } else { var searchCriteria = await BaseSearchCriteriaProvider.GetSearchCriteriaAsync(Keywords, BaseUrl, true, CurrentPage).ConfigureAwait(false); searchCriteria.SortBy = SortBy; searchCriteria.SortDirection = SortDirection; searchCriteria.SelectedFacets.AddRange(SelectedFacets); viewModel = await SearchViewService.GetSearchViewModelAsync(searchCriteria).ConfigureAwait(false); } viewModel.ProductSearchResults.Facets = viewModel.ProductSearchResults.Facets.Where(f => !f.FieldName.StartsWith(SearchConfiguration.CategoryFacetFiledNamePrefix)).ToList(); return(Ok(viewModel)); }
public virtual async Task <SearchCriteria> GetSearchCriteriaAsync(string searchTerms, string baseURL, bool includeFacets, int page) { return(new SearchCriteria { Keywords = searchTerms, NumberOfItemsPerPage = SearchConfiguration.MaxItemsPerPage, IncludeFacets = includeFacets, StartingIndex = (page - 1) * SearchConfiguration.MaxItemsPerPage, Page = page, SortBy = SearchRequestParams.DefaultSortBy, SortDirection = SearchRequestParams.DefaultSortDirection, BaseUrl = baseURL, Scope = ComposerContext.Scope, CultureInfo = ComposerContext.CultureInfo, InventoryLocationIds = await InventoryLocationProvider.GetInventoryLocationIdsForSearchAsync().ConfigureAwait(false), AvailabilityDate = FulfillmentContext.AvailabilityAndPriceDate, AutoCorrect = SearchConfiguration.AutoCorrectSearchTerms, }); }
public virtual async Task <IHttpActionResult> AutoComplete(AutoCompleteSearchViewModel request, int limit = MAXIMUM_AUTOCOMPLETE_RESULT) { var originalSearchTerms = request.Query.Trim(); var searchTerms = SearchTermsTransformationProvider.TransformSearchTerm(originalSearchTerms, ComposerContext.CultureInfo.Name);; var searchCriteria = new SearchCriteria { Keywords = searchTerms, NumberOfItemsPerPage = limit, IncludeFacets = false, StartingIndex = 0, SortBy = "score", SortDirection = "desc", Page = 1, BaseUrl = RequestUtils.GetBaseUrl(Request).ToString(), Scope = ComposerContext.Scope, CultureInfo = ComposerContext.CultureInfo, InventoryLocationIds = await InventoryLocationProvider.GetInventoryLocationIdsForSearchAsync().ConfigureAwait(false), }; var searchResultsViewModel = await SearchViewService.GetSearchViewModelAsync(searchCriteria).ConfigureAwait(false); if (searchResultsViewModel.ProductSearchResults?.TotalCount == 0 && originalSearchTerms != searchTerms) { searchCriteria.Keywords = originalSearchTerms; searchResultsViewModel = await SearchViewService.GetSearchViewModelAsync(searchCriteria).ConfigureAwait(false); } var vm = new AutoCompleteViewModel() { Suggestions = new List <ProductSearchViewModel>() }; if (searchResultsViewModel.ProductSearchResults?.SearchResults?.Count > 0) { vm.Suggestions = searchResultsViewModel.ProductSearchResults.SearchResults.Take(limit) .Select(p => { p.SearchTerm = searchTerms; return(p); }) .ToList(); } return(Ok(vm)); }
protected virtual SearchCriteria BuildProductsSearchCriteria() { var criteria = new SearchCriteria { Keywords = SearchQuery, NumberOfItemsPerPage = SearchConfiguration.MaxItemsPerPage, IncludeFacets = true, StartingIndex = (CurrentPage - 1) * SearchConfiguration.MaxItemsPerPage, SortBy = IsProductsSearchActive ? SortBy: null, SortDirection = IsProductsSearchActive ? SortDirection: null, Page = CurrentPage, BaseUrl = RequestUtils.GetBaseUrl(Request).ToString(), CultureInfo = ComposerContext.CultureInfo, Scope = ComposerContext.Scope, InventoryLocationIds = InventoryLocationProvider.GetInventoryLocationIdsForSearchAsync().Result, AutoCorrect = SearchConfiguration.AutoCorrectSearchTerms }; criteria.SelectedFacets.AddRange(SearchUrlProvider.BuildSelectedFacets(Request.QueryString)); return(criteria); }
protected virtual async Task <IEnumerable <ProductIdentifier> > GetSameCategoryProductIdentifier(GetProductIdentifiersParam getProductIdentifiersParam, string categoryId) { Guard.NotNull(getProductIdentifiersParam, nameof(getProductIdentifiersParam)); Guard.NotNullOrWhiteSpace(categoryId, nameof(categoryId)); var sameCategoryProductIdentifier = new List <ProductIdentifier>(); var productInSameCategoryParam = new GetProductsInSameCategoryParam() { CategoryId = categoryId, CultureInfo = getProductIdentifiersParam.CultureInfo, Scope = getProductIdentifiersParam.Scope, MaxItems = getProductIdentifiersParam.MaxItems, SortBy = "score", InventoryLocationIds = await InventoryLocationProvider.GetInventoryLocationIdsForSearchAsync(), CurrentProductId = getProductIdentifiersParam.ProductId }; var sameCategoryProducts = await RelationshipRepository.GetProductInSameCategoryAsync(productInSameCategoryParam).ConfigureAwait(false); if (sameCategoryProducts.Documents.Any()) { sameCategoryProductIdentifier = sameCategoryProducts.Documents.Select(d => { string variantId = null; if (d.PropertyBag.ContainsKey(VariantPropertyBagKey)) { variantId = d.PropertyBag[VariantPropertyBagKey] as string; } return(new ProductIdentifier { ProductId = d.ProductId, VariantId = variantId }); }).ToList(); } return(sameCategoryProductIdentifier); }
protected virtual List <string> GetInventoryLocationIds() { var ids = InventoryLocationProvider.GetInventoryLocationIdsForSearchAsync().Result; return(ids); }