/// <summary>
            /// Re-directs product search requests to appropriate handlers based on search type.
            /// </summary>
            /// <param name="request">The request to perform a search operation.</param>
            /// <returns>A collection of search results representative of a product.</returns>
            private static EntityDataServiceResponse <ProductSearchResult> ProcessProductSearchRequest(GetProductSearchResultsDataRequest request)
            {
                ThrowIf.Null(request, "request");
                ThrowIf.Null(request.QueryResultSettings, "request.QueryResultSettings");

                if (request.ChannelId <= 0)
                {
                    throw new ArgumentOutOfRangeException("request", request.ChannelId, "Channel identifier cannot be less than zero.");
                }

                if (request.CatalogId < 0)
                {
                    throw new ArgumentOutOfRangeException("request", request.CatalogId, "Catalog identifier cannot be less than zero.");
                }

                if (request.RequestContext.GetPrincipal().ChannelId != request.ChannelId)
                {
                    throw new ArgumentOutOfRangeException("request", "GetProductSearchResultsDataRequest can only search for products in the current channel.");
                }

                PagedResult <ProductSearchResult> results;

                if (request.CategoryId > 0)
                {
                    results = new SearchProductsByCategoryIdProcedure(request).Execute();

                    return(new EntityDataServiceResponse <ProductSearchResult>(results));
                }

                if (!string.IsNullOrWhiteSpace(request.SearchText))
                {
                    throw new NotImplementedException("Will be implemented soon.");
                }

                throw new InvalidOperationException("Only product search by category id and text is supported. Please provide a valid category id or search text.");
            }
            private static SearchProductsServiceResponse SearchProducts(SearchProductsServiceRequest request)
            {
                ThrowIf.Null(request, "request");
                ThrowIf.Null(request.QueryResultSettings, "request.QueryResultSettings");

                if (request.ChannelId < 0)
                {
                    throw new ArgumentOutOfRangeException("request", request.ChannelId, "Channel identifier cannot be less than zero.");
                }

                if (request.CatalogId < 0)
                {
                    throw new ArgumentOutOfRangeException("request", request.CatalogId, "Catalog identifier cannot be less than zero.");
                }

                long currentChannelId = request.RequestContext.GetPrincipal().ChannelId;

                if (request.ChannelId != currentChannelId && request.CategoryId.HasValue)
                {
                    RemoteSearchProductsRealtimeRequest realtimeRequest  = new RemoteSearchProductsRealtimeRequest(request.ChannelId, request.CatalogId, request.CategoryId.Value, request.QueryResultSettings);
                    SearchProductsRealtimeResponse      realtimeResponse = request.RequestContext.Execute <SearchProductsRealtimeResponse>(realtimeRequest);

                    return(new SearchProductsServiceResponse(realtimeResponse.ProductSearchResults));
                }
                else if (request.ChannelId != currentChannelId && !string.IsNullOrWhiteSpace(request.SearchText))
                {
                    var realtimeRequest = new RemoteSearchProductsRealtimeRequest(request.ChannelId, request.CatalogId, request.SearchText, request.QueryResultSettings);
                    SearchProductsRealtimeResponse realtimeResponse = request.RequestContext.Execute <SearchProductsRealtimeResponse>(realtimeRequest);

                    return(new SearchProductsServiceResponse(realtimeResponse.ProductSearchResults));
                }

                GetProductSearchResultsDataRequest dataRequest = null;

                if (request.ChannelId == currentChannelId && request.CategoryId.HasValue)
                {
                    dataRequest = new GetProductSearchResultsDataRequest(request.ChannelId, request.CatalogId, request.CategoryId.Value, request.QueryResultSettings);
                }
                else if (request.ChannelId == currentChannelId && !string.IsNullOrWhiteSpace(request.SearchText))
                {
                    GetProductBarcodeDataRequest  productBarcodeRequest  = new GetProductBarcodeDataRequest(request.SearchText);
                    GetProductBarcodeDataResponse productBarcodeResponse = request.RequestContext.Execute <GetProductBarcodeDataResponse>(productBarcodeRequest);

                    if (productBarcodeResponse != null && productBarcodeResponse.Barcode != null && !string.IsNullOrWhiteSpace(productBarcodeResponse.Barcode.ItemId))
                    {
                        dataRequest = new GetProductSearchResultsDataRequest(request.ChannelId, request.CatalogId, productBarcodeResponse.Barcode.ItemId, request.QueryResultSettings);
                        dataRequest.UseFuzzySearch = false;
                    }
                    else
                    {
                        dataRequest = new GetProductSearchResultsDataRequest(request.ChannelId, request.CatalogId, request.SearchText, request.QueryResultSettings);
                    }
                }
                else
                {
                    throw new NotSupportedException("A valid category identifier or search text has not been specified. One of these values need to be set correctly.");
                }

                var dataResponse = request.RequestContext.Execute <EntityDataServiceResponse <ProductSearchResult> >(dataRequest);

                return(new SearchProductsServiceResponse(dataResponse.PagedEntityCollection));
            }
Example #3
0
            /// <summary>
            /// Re-directs product search requests to appropriate handlers based on search type.
            /// </summary>
            /// <param name="request">The request to perform a search operation.</param>
            /// <returns>A collection of search results representative of a product.</returns>
            private static EntityDataServiceResponse <ProductSearchResult> ProcessProductSearchRequest(GetProductSearchResultsDataRequest request)
            {
                ThrowIf.Null(request, "request");
                ThrowIf.Null(request.QueryResultSettings, "request.QueryResultSettings");

                if (request.RequestContext.GetPrincipal().ChannelId != request.ChannelId)
                {
                    throw new ArgumentOutOfRangeException("request", "GetProductSearchResultsDataRequest can only search for products in the current channel.");
                }

                PagedResult <ProductSearchResult> results = null;
                var channelDateTime = request.RequestContext.GetNowInChannelTimeZone().DateTime;

                if (request.CategoryId.HasValue)
                {
                    results = SearchByCategoryId(request.ChannelId, request.CatalogId, channelDateTime, request.RequestContext.LanguageId, (long)request.CategoryId, request.RequestContext, request.QueryResultSettings);
                }

                if (!string.IsNullOrWhiteSpace(request.SearchText))
                {
                    results = SearchByText(request.ChannelId, request.CatalogId, channelDateTime, request.RequestContext.LanguageId, request.SearchText, request.UseFuzzySearch, request.RequestContext, request.QueryResultSettings);
                }

                return(new EntityDataServiceResponse <ProductSearchResult>(results));
            }
Example #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SearchProductsByCategoryIdProcedure"/> class.
 /// </summary>
 /// <param name="request">The data request.</param>
 public SearchProductsByCategoryIdProcedure(GetProductSearchResultsDataRequest request)
 {
     this.request = request;
 }