public async Task <ActionResult <ShoppingCartSearchResult> > SearchLists([FromBody] CartSearchCriteria searchCriteria) { if (searchCriteria == null) { searchCriteria = new CartSearchCriteria(); } //restricting query to lists belongs to other customers searchCriteria.StoreId = WorkContext.CurrentStore.Id; searchCriteria.Customer = WorkContext.CurrentUser; searchCriteria.Currency = WorkContext.CurrentCurrency; searchCriteria.Language = WorkContext.CurrentLanguage; var cartPagedList = await _cartService.SearchCartsAsync(searchCriteria); var result = new ShoppingCartSearchResult { Results = cartPagedList.ToArray(), TotalCount = cartPagedList.TotalItemCount }; var productIds = result.Results.SelectMany(x => x.Items).Select(x => x.ProductId).Distinct().ToArray(); var products = await _catalogService.GetProductsAsync(productIds, Model.Catalog.ItemResponseGroup.ItemSmall | Model.Catalog.ItemResponseGroup.ItemWithPrices | Model.Catalog.ItemResponseGroup.Inventory); foreach (var item in result.Results.SelectMany(x => x.Items).ToArray()) { item.Product = products.FirstOrDefault(x => x.Id == item.ProductId); } return(result); }
public IHttpActionResult Search(ShoppingCartSearchCriteria criteria) { var result = _searchService.Search(criteria); var retVal = new ShoppingCartSearchResult { Results = result.Results.ToList(), TotalCount = result.TotalCount }; return(Ok(retVal)); }