コード例 #1
0
        protected virtual async Task AddLabelsAsync(IList <Aggregation> aggregations, string catalogId)
        {
            var allProperties = await _propertyService.GetAllCatalogPropertiesAsync(catalogId);

            foreach (var aggregation in aggregations)
            {
                // There can be many properties with the same name
                var properties = allProperties.Where(p => p.Name.EqualsInvariant(aggregation.Field)).ToArray();

                if (properties.Any())
                {
                    var allPropertyLabels = properties.SelectMany(p => p.DisplayNames)
                                            .Select(n => new AggregationLabel {
                        Language = n.LanguageCode, Label = n.Name
                    })
                                            .ToArray();

                    aggregation.Labels = GetFirstLabelForEachLanguage(allPropertyLabels);

                    var dictionaryItemsSearchResult = await _propDictItemsSearchService.SearchAsync(new PropertyDictionaryItemSearchCriteria { PropertyIds = properties.Select(x => x.Id).ToArray(), Take = int.MaxValue });

                    var allDictItemsMap = dictionaryItemsSearchResult.Results.GroupBy(x => x.Alias)
                                          .ToDictionary(x => x.Key, x => x.SelectMany(dictItem => dictItem.LocalizedValues)
                                                        .Select(localizedValue => new AggregationLabel {
                        Language = localizedValue.LanguageCode, Label = localizedValue.Value
                    }));

                    foreach (var aggregationItem in aggregation.Items)
                    {
                        var alias = aggregationItem.Value?.ToString();
                        if (!string.IsNullOrEmpty(alias))
                        {
                            if (allDictItemsMap.TryGetValue(alias, out var labels))
                            {
                                aggregationItem.Labels = GetFirstLabelForEachLanguage(labels.ToArray());
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
        public async Task <ActionResult <string[]> > GetPropertyValues(string storeId, string propertyName)
        {
            var result = Array.Empty <string>();
            var store  = await _storeService.GetByIdAsync(storeId);

            if (store == null)
            {
                return(NoContent());
            }

            //CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.ReadBrowseFilters, store);
            var catalogPropertiesSearchResult = await _propertySearchService.SearchPropertiesAsync(new PropertySearchCriteria { PropertyNames = new[] { propertyName }, CatalogId = store.Catalog, Take = 1 });

            var property = catalogPropertiesSearchResult.Results.FirstOrDefault(p => p.Name.EqualsInvariant(propertyName) && p.Dictionary);

            if (property != null)
            {
                var searchResult = await _propDictItemsSearchService.SearchAsync(new PropertyDictionaryItemSearchCriteria { PropertyIds = new[] { property.Id }, Take = int.MaxValue });

                result = searchResult.Results.Select(x => x.Alias).Distinct().ToArray();
            }
            return(Ok(result));
        }
コード例 #3
0
        public async Task DoExportAsync(Stream outStream, ExportImportOptions options, Action <ExportImportProgressInfo> progressCallback, ICancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            var progressInfo = new ExportImportProgressInfo {
                Description = "loading data..."
            };

            progressCallback(progressInfo);

            using (var sw = new StreamWriter(outStream))
                using (var writer = new JsonTextWriter(sw))
                {
                    await writer.WriteStartObjectAsync();

                    #region Export catalogs
                    progressInfo.Description = "Catalogs exporting...";
                    progressCallback(progressInfo);

                    await writer.WritePropertyNameAsync("Catalogs");

                    await writer.SerializeJsonArrayWithPagingAsync(_jsonSerializer, _batchSize, async (skip, take) =>
                    {
                        var searchResult = (await _catalogService.GetCatalogsListAsync()).ToArray();
                        return(new GenericSearchResult <Catalog> {
                            Results = searchResult, TotalCount = searchResult.Length
                        });
                    }, (processedCount, totalCount) =>
                    {
                        progressInfo.Description = $"{ processedCount } of { totalCount } catalogs have been exported";
                        progressCallback(progressInfo);
                    }, cancellationToken);

                    #endregion

                    #region Export categories
                    progressInfo.Description = "Categories exporting...";
                    progressCallback(progressInfo);

                    await writer.WritePropertyNameAsync("Categories");

                    await writer.SerializeJsonArrayWithPagingAsync(_jsonSerializer, _batchSize, async (skip, take) =>
                    {
                        var searchResult = await _categorySearchService.SearchCategoriesAsync(new CategorySearchCriteria {
                            Skip = skip, Take = take
                        });
                        var categories = searchResult.Results;
                        if (options.HandleBinaryData)
                        {
                            LoadImages(categories.OfType <IHasImages>().ToArray(), progressInfo);
                        }

                        return(new GenericSearchResult <Category> {
                            Results = categories, TotalCount = searchResult.TotalCount
                        });
                    }, (processedCount, totalCount) =>
                    {
                        progressInfo.Description = $"{ processedCount } of { totalCount } Categories have been exported";
                        progressCallback(progressInfo);
                    }, cancellationToken);

                    #endregion

                    #region Export properties
                    progressInfo.Description = "Properties exporting...";
                    progressCallback(progressInfo);

                    await writer.WritePropertyNameAsync("Properties");

                    await writer.SerializeJsonArrayWithPagingAsync(_jsonSerializer, _batchSize, async (skip, take) =>
                    {
                        var searchResult = await _propertySearchService.SearchPropertiesAsync(new PropertySearchCriteria {
                            Skip = skip, Take = take
                        });
                        return(new GenericSearchResult <Property> {
                            Results = searchResult.Results, TotalCount = searchResult.TotalCount
                        });
                    }, (processedCount, totalCount) =>
                    {
                        progressInfo.Description = $"{ processedCount } of { totalCount } properties have been exported";
                        progressCallback(progressInfo);
                    }, cancellationToken);

                    #endregion

                    #region Export propertyDictionaryItems
                    progressInfo.Description = "PropertyDictionaryItems exporting...";
                    progressCallback(progressInfo);

                    await writer.WritePropertyNameAsync("PropertyDictionaryItems");

                    await writer.SerializeJsonArrayWithPagingAsync(_jsonSerializer, _batchSize, async (skip, take) =>
                    {
                        var searchResult = await _propertyDictionarySearchService.SearchAsync(new PropertyDictionaryItemSearchCriteria {
                            Skip = skip, Take = take
                        });
                        return(new GenericSearchResult <PropertyDictionaryItem> {
                            Results = searchResult.Results, TotalCount = searchResult.TotalCount
                        });
                    }, (processedCount, totalCount) =>
                    {
                        progressInfo.Description = $"{ processedCount } of { totalCount } property dictionary items have been exported";
                        progressCallback(progressInfo);
                    }, cancellationToken);

                    #endregion

                    #region Export products
                    progressInfo.Description = "Products exporting...";
                    progressCallback(progressInfo);

                    await writer.WritePropertyNameAsync("Products");

                    await writer.SerializeJsonArrayWithPagingAsync(_jsonSerializer, _batchSize, async (skip, take) =>
                    {
                        var searchResult = await _productSearchService.SearchProductsAsync(new ProductSearchCriteria {
                            Skip = skip, Take = take
                        });
                        if (options.HandleBinaryData)
                        {
                            LoadImages(searchResult.Results.OfType <IHasImages>().ToArray(), progressInfo);
                        }
                        return(new GenericSearchResult <CatalogProduct> {
                            Results = searchResult.Results, TotalCount = searchResult.TotalCount
                        });
                    }, (processedCount, totalCount) =>
                    {
                        progressInfo.Description = $"{ processedCount } of { totalCount } Products have been exported";
                        progressCallback(progressInfo);
                    }, cancellationToken);

                    #endregion

                    await writer.WriteEndObjectAsync();

                    await writer.FlushAsync();
                }
        }
コード例 #4
0
        public async Task <ActionResult <PropertyDictionaryItem[]> > GetPropertyValues(string propertyId, [FromQuery] string keyword = null)
        {
            var dictValues = await _propertyDictionarySearchService.SearchAsync(new PropertyDictionaryItemSearchCriteria { Keyword = keyword, PropertyIds = new[] { propertyId }, Take = int.MaxValue });

            return(Ok(dictValues.Results));
        }
コード例 #5
0
        public async Task <ActionResult <PropertyDictionaryItem[]> > SearchPropertyDictionaryItems([FromBody] PropertyDictionaryItemSearchCriteria criteria)
        {
            var result = await _propertyDictionarySearchService.SearchAsync(criteria);

            return(Ok(result));
        }