private static ProductSearchRealtimeResponse GetRemoteProductsByCategory(GetRemoteProductsByCategoryRealtimeRequest request) { var client = new TransactionServiceClient(request.RequestContext); long currentChannelId = request.RequestContext.GetPrincipal().ChannelId; var products = client.GetProductsByCategory( currentChannelId, request.ChannelId, request.CatalogId.GetValueOrDefault(), request.CategoryId, request.QueryResultSettings.Paging.Skip, request.QueryResultSettings.Paging.Top, request.AttributeIds, request.IncludeProductsFromDescendantCategories); var results = new ProductSearchResultContainer(products); return(new ProductSearchRealtimeResponse(results)); }
private static ProductSearchServiceResponse SearchRemoteProducts(ProductSearchServiceRequest request) { ProductSearchResultContainer results = null; bool searchByProduct = request.QueryCriteria.Ids != null && request.QueryCriteria.Ids.Any(); bool searchByCategory = request.QueryCriteria.CategoryIds != null && request.QueryCriteria.CategoryIds.Any(); bool searchByKeyword = !string.IsNullOrEmpty(request.QueryCriteria.SearchCondition); if (searchByCategory && request.QueryCriteria.CategoryIds.HasMultiple()) { throw new NotSupportedException("Only a single category identifier can be specified when searching remotely."); } if (!(searchByProduct ^ searchByCategory ^ searchByKeyword)) { throw new NotSupportedException("When searching remotely you can search only by id, category or keyword."); } string attributeIds = string.Concat(RetailProductChannelProductAttributeId.ProductName, ",", RetailProductChannelProductAttributeId.Image); if (searchByProduct) { GetProductDataRealtimeRequest getProductDataServiceRequest = new GetProductDataRealtimeRequest(request.QueryCriteria.Ids); var getProductDataResponse = request.RequestContext.Execute <GetProductDataRealtimeResponse>(getProductDataServiceRequest); var productsXml = getProductDataResponse.ProductDataXml; var manager = new ProductDataManager(request.RequestContext); manager.SaveProductData(productsXml); // Checks if the downloaded product contains a kit product and retrieve the component and substitutes of the kit product. RetrieveComponentProducts(request, productsXml); // Reset the channel context since the remote product data has been saved locally. request.QueryCriteria.Context.ChannelId = request.RequestContext.GetPrincipal().ChannelId; request.QueryCriteria.Context.CatalogId = 0; results = SearchProductsLocal(request).ProductSearchResult; } else if (searchByCategory) { var getProductsByCategoryRequest = new GetRemoteProductsByCategoryRealtimeRequest( request.QueryCriteria.Context.ChannelId.Value, request.QueryCriteria.Context.CatalogId, request.QueryCriteria.CategoryIds.First(), attributeIds, request.QueryCriteria.IncludeProductsFromDescendantCategories); getProductsByCategoryRequest.QueryResultSettings = request.QueryResultSettings; var response = request.RequestContext.Execute <ProductSearchRealtimeResponse>(getProductsByCategoryRequest); results = response.ProductSearchResult; } else if (searchByKeyword) { var getProductsByKeywordRequest = new GetRemoteProductsByKeywordRealtimeRequest( request.QueryCriteria.Context.ChannelId.Value, request.QueryCriteria.Context.CatalogId, request.QueryCriteria.SearchCondition, attributeIds); getProductsByKeywordRequest.QueryResultSettings = request.QueryResultSettings; var response = request.RequestContext.Execute <ProductSearchRealtimeResponse>(getProductsByKeywordRequest); results = response.ProductSearchResult; } return(new ProductSearchServiceResponse(results)); }