public override async Task <EkKioskProductSearchInEuropeGetResponse> ExecuteAsync(EkKioskProductSearchInEuropeGetRequest request) { //var kioskId = _currentUser.Id; //if (kioskId == 75) //{ // return await MySpecialLogicAsync(); //} var categoryId = request.CategoryId; if (string.IsNullOrEmpty(categoryId)) { categoryId = AutomotiveCategoryId; } OfferStateEnum offerState; switch (request.State) { case EkProductStateEnum.New: offerState = OfferStateEnum.New; break; case EkProductStateEnum.Used: offerState = OfferStateEnum.Used; break; case EkProductStateEnum.Recovered: offerState = OfferStateEnum.Recovered; break; case EkProductStateEnum.Broken: offerState = OfferStateEnum.Broken; break; default: offerState = OfferStateEnum.All; break; } OfferSortingEnum offerSorting; switch (request.Sorting) { case EkProductSearchSortingEnum.PriceAscending: offerSorting = OfferSortingEnum.PriceAsc; break; case EkProductSearchSortingEnum.PriceDescending: offerSorting = OfferSortingEnum.PriceDesc; break; default: case EkProductSearchSortingEnum.Default: offerSorting = OfferSortingEnum.Relevance; break; } // cancellation token var cancellationToken = _httpContextAccessor.HttpContext?.RequestAborted ?? CancellationToken.None; var searchOffersResponse = await _allegroPlClient.SearchOffersAsync( request.Term, request.TranslatedTerm, categoryId, offerState, offerSorting, request.From, request.Count, cancellationToken); try { await _allegroPlClient.ApplyTranslations(_translateService, searchOffersResponse.Offers, request.Term, request.TranslatedTerm, cancellationToken); } catch { } EkProduct[] products; if (searchOffersResponse.Offers?.Length > 0) { var exchangeRate = 6;//await GetExchangeRateAsync(); products = searchOffersResponse.Offers .Select(x => EkConvertHelper.EkAllegroPlOfferToProduct(x, exchangeRate)) .ToArray(); } else { products = new EkProduct[0]; } return(new EkKioskProductSearchInEuropeGetResponse() { Products = products, Total = searchOffersResponse.Total, TranslatedTerm = searchOffersResponse.TranslatedPhrase, }); }
public override async Task <EkKioskProductAndReplacementsByPartNumberGetResponse> ExecuteAsync(EkKioskProductAndReplacementsByPartNumberGetRequest request) { Assure.ArgumentNotNull(request.PartNumberBrand, nameof(request.PartNumberBrand)); Assure.ArgumentNotNull(request.PartNumberBrand.ProductKey, nameof(request.PartNumberBrand.ProductKey)); Assure.ArgumentNotNull(request.PartNumberBrand.PartNumber, nameof(request.PartNumberBrand.PartNumber)); var response = new EkKioskProductAndReplacementsByPartNumberGetResponse(); // cancellation token var cancellationToken = _httpContextAccessor.HttpContext?.RequestAborted ?? CancellationToken.None; using (var searchIndexClient = AzureSearchHelper.CreateSearchIndexClient(_ekSearchSettings.ServiceName, _ekSearchSettings.QueryKey)) { searchIndexClient.IndexName = _ekSearchSettings.ProductsIndexName; // FIND PRODUCT try { var indexProduct = await searchIndexClient.Documents.GetAsync <IndexProduct>( request.PartNumberBrand.ProductKey, cancellationToken : cancellationToken); response.Product = EkConvertHelper.EkNewIndexProductToProduct(indexProduct); // todo: add search by Brand/PartNumber to find all direct matches since many products sources are supported // it's not done since new product search model is planned anyway } catch (CloudException) { response.Product = EkConvertHelper.EkOmegaPartNumberBrandToProduct(request.PartNumberBrand); } // FIND REPLACEMENTS var cleanedPartNumber = PartNumberCleaner.GetCleanedPartNumber(request.PartNumberBrand.PartNumber); // TecDoc replacements // todo: add cancellationToken support to proxy based clients var tecDocReplacements = await _tecDocWsClient.SearchByArticleNumberAsync(cleanedPartNumber); tecDocReplacements = tecDocReplacements // except direct match .Where(x => x.NumberType != ArticleNumberTypeEnum.ArticleNumber) .ToArray(); var replacementCleanedBrandPartNumbers = tecDocReplacements .Select(x => PartNumberCleaner.GetCleanedBrandPartNumber(x.BrandName, x.ArticleNo)) .Take(100) .ToArray(); if (replacementCleanedBrandPartNumbers.Length > 0) { var replacementsIndexSearchParameters = new SearchParameters() { Top = 100, SearchFields = new[] { "cleanedBrandPartNumber" }, }; var searchTerm = string.Join("|", replacementCleanedBrandPartNumbers); var searchResult = await searchIndexClient.Documents.SearchAsync <IndexProduct>( searchTerm, replacementsIndexSearchParameters, cancellationToken : cancellationToken); response.Replacements = searchResult.Results .Select(x => EkConvertHelper.EkNewIndexProductToProduct(x.Document)) .ToArray(); } else { response.Replacements = new EkProduct[0]; } return(response); } }
public override async Task <EkKioskProductSearchByNameGetResponse> ExecuteAsync(EkKioskProductSearchByNameGetRequest request) { if (string.IsNullOrEmpty(request.Term) || request.Term.Length < 3) { return(new EkKioskProductSearchByNameGetResponse() { Products = new EkProduct[0], }); } // cancellation token var cancellationToken = _httpContextAccessor.HttpContext?.RequestAborted ?? CancellationToken.None; using (var searchIndexClient = AzureSearchHelper.CreateSearchIndexClient(_ekSearchSettings.ServiceName, _ekSearchSettings.QueryKey)) { searchIndexClient.IndexName = _ekSearchSettings.ProductsIndexName; // paging var indexSearchParameters = new SearchParameters() { Skip = request.From, Top = request.Count, IncludeTotalResultCount = request.IncludeTotal, SearchFields = GetLanguageSpecificTextFields(request.LanguageCode), ScoringProfile = SearchConstants.BoostNameScoringProfileName, }; // sorting switch (request.Sorting) { case EkProductSearchSortingEnum.PriceAscending: indexSearchParameters.OrderBy = new[] { "price asc" }; break; case EkProductSearchSortingEnum.PriceDescending: indexSearchParameters.OrderBy = new[] { "price desc" }; break; case EkProductSearchSortingEnum.Default: default: // no sorting break; } // term var term = request.Term; var searchResult = await searchIndexClient.Documents.SearchAsync <IndexProduct>( term, indexSearchParameters, cancellationToken : cancellationToken); var products = searchResult.Results .Select(x => EkConvertHelper.EkNewIndexProductToProduct(x.Document)) .ToArray(); var total = searchResult.Count ?? 0; return(new EkKioskProductSearchByNameGetResponse() { Products = products, Total = total, }); } }
public override async Task <EkKioskProductSearchByCategoryGetResponse> ExecuteAsync(EkKioskProductSearchByCategoryGetRequest request) { var response = new EkKioskProductSearchByCategoryGetResponse(); // cancellation token var cancellationToken = _httpContextAccessor.HttpContext?.RequestAborted ?? CancellationToken.None; // todo: add cancellationToken support to proxy based clients // determine TecDoc car type of modification first CarTypeEnum carType; // request categories for cars first var categories = await _tecDocWsClient.GetCategoriesAsync(CarTypeEnum.Car, request.ModificationId, null, childNodes : false); if (categories?.Length > 0) { carType = CarTypeEnum.Car; } else { // then request for trucks categories = await _tecDocWsClient.GetCategoriesAsync(CarTypeEnum.Truck, request.ModificationId, null, childNodes : false); if (categories?.Length > 0) { carType = CarTypeEnum.Truck; } else { return(response); } } const int MaxProductCount = 200; // TecDoc articles var tecDocProducts = await _tecDocWsClient.GetArticlesCompactInfoAsync(carType, request.ModificationId, request.CategoryId); var productCleanedBrandPartNumbers = tecDocProducts .Select(x => PartNumberCleaner.GetCleanedBrandPartNumber(x.BrandName, x.ArticleNo)) .Take(MaxProductCount) .ToArray(); if (productCleanedBrandPartNumbers.Length == 0) { return(response); } // FIND PRODUCTS IN STOCK using (var searchIndexClient = AzureSearchHelper.CreateSearchIndexClient(_ekSearchSettings.ServiceName, _ekSearchSettings.QueryKey)) { searchIndexClient.IndexName = _ekSearchSettings.ProductsIndexName; var replacementsIndexSearchParameters = new SearchParameters() { Top = MaxProductCount, SearchFields = new[] { "cleanedBrandPartNumber" }, }; var searchTerm = string.Join("|", productCleanedBrandPartNumbers); var searchResult = await searchIndexClient.Documents.SearchAsync <IndexProduct>( searchTerm, replacementsIndexSearchParameters, cancellationToken : cancellationToken); response.Products = searchResult.Results .Select(x => EkConvertHelper.EkNewIndexProductToProduct(x.Document)) .ToArray(); return(response); } }