Пример #1
0
        public void MapListActions(ProductSummaryModel model, IPagingOptions entity, string defaultPageSizeOptions)
        {
            var searchQuery = _catalogSearchQueryFactory.Current;

            // View mode
            model.AllowViewModeChanging = _catalogSettings.AllowProductViewModeChanging;

            // Sorting
            model.AllowSorting = _catalogSettings.AllowProductSorting;
            if (model.AllowSorting)
            {
                model.CurrentSortOrder = searchQuery?.CustomData.Get("CurrentSortOrder").Convert <int?>();

                model.AvailableSortOptions = _services.Cache.Get("pres:productlistsortoptions-{0}".FormatInvariant(_services.WorkContext.WorkingLanguage.Id), () =>
                {
                    var dict = new Dictionary <int, string>();
                    foreach (ProductSortingEnum enumValue in Enum.GetValues(typeof(ProductSortingEnum)))
                    {
                        if (enumValue == ProductSortingEnum.CreatedOnAsc || enumValue == ProductSortingEnum.Initial)
                        {
                            continue;
                        }

                        dict[(int)enumValue] = enumValue.GetLocalizedEnum(_localizationService, _services.WorkContext);
                    }

                    return(dict);
                });

                if (!searchQuery.Origin.IsCaseInsensitiveEqual("Search/Search"))
                {
                    model.RelevanceSortOrderName = T("Products.Sorting.Featured");
                    if ((int)ProductSortingEnum.Relevance == (model.CurrentSortOrder ?? 1))
                    {
                        model.CurrentSortOrderName = model.RelevanceSortOrderName;
                    }
                }

                if (model.CurrentSortOrderName.IsEmpty())
                {
                    model.CurrentSortOrderName = model.AvailableSortOptions.Get(model.CurrentSortOrder ?? 1) ?? model.AvailableSortOptions.First().Value;
                }
            }

            // Pagination
            if (entity?.AllowCustomersToSelectPageSize ?? _catalogSettings.AllowCustomersToSelectPageSize)
            {
                try
                {
                    model.AvailablePageSizes = (entity?.PageSizeOptions.NullEmpty() ?? defaultPageSizeOptions).Convert <List <int> >();
                }
                catch
                {
                    model.AvailablePageSizes = new int[] { 12, 24, 36, 48, 72, 120 };
                }
            }

            model.AllowFiltering = true;
        }
        // GET: ProductSummary
        public ActionResult Index(int id)
        {
            ProductSummaryService productSummaryService = new ProductSummaryService();
            ProductSummaryModel   properties            = new ProductSummaryModel
            {
                //Array is [ManufacturerName, Series, Model, ModelYear]
                description = productSummaryService.getDescription(id), //Change this 1 to the productID that's passed in.

                //Array is [PropertyName, IsType, Value, HasMinMax, Max, Min]
                properties = productSummaryService.getProperties(id) //Change this 1 to the productID that's passed in.
            };

            ViewData["propertiesObject"] = properties;
            return(View(properties));
        }
Пример #3
0
        public virtual ProductSummaryModel MapProductSummaryModel(IPagedList <Product> products, ProductSummaryMappingSettings settings)
        {
            Guard.NotNull(products, nameof(products));

            if (settings == null)
            {
                settings = new ProductSummaryMappingSettings();
            }

            using (_services.Chronometer.Step("MapProductSummaryModel"))
            {
                // PERF!!
                var store                    = _services.StoreContext.CurrentStore;
                var customer                 = _services.WorkContext.CurrentCustomer;
                var currency                 = _services.WorkContext.WorkingCurrency;
                var allowPrices              = _services.Permissions.Authorize(StandardPermissionProvider.DisplayPrices);
                var sllowShoppingCart        = _services.Permissions.Authorize(StandardPermissionProvider.EnableShoppingCart);
                var allowWishlist            = _services.Permissions.Authorize(StandardPermissionProvider.EnableWishlist);
                var taxDisplayType           = _services.WorkContext.GetTaxDisplayTypeFor(customer, store.Id);
                var cachedManufacturerModels = new Dictionary <int, ManufacturerOverviewModel>();

                string taxInfo   = T(taxDisplayType == TaxDisplayType.IncludingTax ? "Tax.InclVAT" : "Tax.ExclVAT");
                var    legalInfo = "";

                var res = new Dictionary <string, LocalizedString>(StringComparer.OrdinalIgnoreCase)
                {
                    { "Products.CallForPrice", T("Products.CallForPrice") },
                    { "Products.PriceRangeFrom", T("Products.PriceRangeFrom") },
                    { "Media.Product.ImageLinkTitleFormat", T("Media.Product.ImageLinkTitleFormat") },
                    { "Media.Product.ImageAlternateTextFormat", T("Media.Product.ImageAlternateTextFormat") },
                    { "Products.DimensionsValue", T("Products.DimensionsValue") },
                    { "Common.AdditionalShippingSurcharge", T("Common.AdditionalShippingSurcharge") }
                };

                if (settings.MapLegalInfo)
                {
                    if (_topicService.Value.GetTopicBySystemName("ShippingInfo", store.Id) == null)
                    {
                        legalInfo = T("Tax.LegalInfoShort2").Text.FormatInvariant(taxInfo);
                    }
                    else
                    {
                        var shippingInfoLink = _urlHelper.RouteUrl("Topic", new { SystemName = "shippinginfo" });
                        legalInfo = T("Tax.LegalInfoShort").Text.FormatInvariant(taxInfo, shippingInfoLink);
                    }
                }

                using (var scope = new DbContextScope(ctx: _services.DbContext, autoCommit: false, validateOnSave: false))
                {
                    // Run in uncommitting scope, because pictures could be updated (IsNew property)
                    var batchContext = _dataExporter.Value.CreateProductExportContext(products);

                    if (settings.MapPrices)
                    {
                        batchContext.AppliedDiscounts.LoadAll();
                        batchContext.TierPrices.LoadAll();
                    }

                    if (settings.MapAttributes || settings.MapColorAttributes)
                    {
                        batchContext.Attributes.LoadAll();
                    }

                    if (settings.MapManufacturers)
                    {
                        batchContext.ProductManufacturers.LoadAll();
                    }

                    if (settings.MapSpecificationAttributes)
                    {
                        batchContext.SpecificationAttributes.LoadAll();
                    }

                    var model = new ProductSummaryModel(products)
                    {
                        ViewMode                          = settings.ViewMode,
                        GridColumnSpan                    = _catalogSettings.GridStyleListColumnSpan,
                        ShowSku                           = _catalogSettings.ShowProductSku,
                        ShowWeight                        = _catalogSettings.ShowWeight,
                        ShowDimensions                    = settings.MapDimensions,
                        ShowLegalInfo                     = settings.MapLegalInfo,
                        ShowDescription                   = settings.MapShortDescription,
                        ShowFullDescription               = settings.MapFullDescription,
                        ShowRatings                       = settings.MapReviews,
                        ShowDeliveryTimes                 = settings.MapDeliveryTimes,
                        ShowPrice                         = settings.MapPrices,
                        ShowBasePrice                     = settings.MapPrices && _catalogSettings.ShowBasePriceInProductLists && settings.ViewMode != ProductSummaryViewMode.Mini,
                        ShowShippingSurcharge             = settings.MapPrices && settings.ViewMode != ProductSummaryViewMode.Mini,
                        ShowButtons                       = settings.ViewMode != ProductSummaryViewMode.Mini,
                        ShowBrand                         = settings.MapManufacturers,
                        ForceRedirectionAfterAddingToCart = settings.ForceRedirectionAfterAddingToCart,
                        CompareEnabled                    = _catalogSettings.CompareProductsEnabled,
                        WishlistEnabled                   = _permissionService.Value.Authorize(StandardPermissionProvider.EnableWishlist),
                        BuyEnabled                        = !_catalogSettings.HideBuyButtonInLists,
                        ThumbSize                         = settings.ThumbnailSize,
                        ShowDiscountBadge                 = _catalogSettings.ShowDiscountSign,
                        ShowNewBadge                      = _catalogSettings.LabelAsNewForMaxDays.HasValue
                    };

                    var mapItemContext = new MapProductSummaryItemContext
                    {
                        BatchContext             = batchContext,
                        CachedManufacturerModels = cachedManufacturerModels,
                        Currency          = currency,
                        LegalInfo         = legalInfo,
                        Model             = model,
                        Resources         = res,
                        Settings          = settings,
                        Customer          = customer,
                        Store             = store,
                        AllowPrices       = allowPrices,
                        AllowShoppingCart = sllowShoppingCart,
                        AllowWishlist     = allowWishlist,
                        TaxDisplayType    = taxDisplayType
                    };

                    foreach (var product in products)
                    {
                        MapProductSummaryItem(product, mapItemContext);
                    }

                    _services.DisplayControl.AnnounceRange(products);

                    scope.Commit();

                    batchContext.Clear();

                    // don't show stuff without data at all
                    model.ShowDescription = model.ShowDescription && model.Items.Any(x => x.ShortDescription.HasValue());
                    model.ShowBrand       = model.ShowBrand && model.Items.Any(x => x.Manufacturer != null);

                    return(model);
                }
            }
        }
Пример #4
0
        public virtual ProductSummaryModel MapProductSummaryModel(IPagedList <Product> products, ProductSummaryMappingSettings settings)
        {
            Guard.NotNull(products, nameof(products));

            if (settings == null)
            {
                settings = new ProductSummaryMappingSettings();
            }

            using (_services.Chronometer.Step("MapProductSummaryModel"))
            {
                var model = new ProductSummaryModel(products)
                {
                    ViewMode                          = settings.ViewMode,
                    GridColumnSpan                    = _catalogSettings.GridStyleListColumnSpan,
                    ShowSku                           = _catalogSettings.ShowProductSku,
                    ShowWeight                        = _catalogSettings.ShowWeight,
                    ShowDimensions                    = settings.MapDimensions,
                    ShowLegalInfo                     = settings.MapLegalInfo,
                    ShowDescription                   = settings.MapShortDescription,
                    ShowFullDescription               = settings.MapFullDescription,
                    ShowRatings                       = settings.MapReviews,
                    ShowDeliveryTimes                 = settings.MapDeliveryTimes,
                    ShowPrice                         = settings.MapPrices,
                    ShowBasePrice                     = settings.MapPrices && _catalogSettings.ShowBasePriceInProductLists && settings.ViewMode != ProductSummaryViewMode.Mini,
                    ShowShippingSurcharge             = settings.MapPrices && settings.ViewMode != ProductSummaryViewMode.Mini,
                    ShowButtons                       = settings.ViewMode != ProductSummaryViewMode.Mini,
                    ShowBrand                         = settings.MapManufacturers,
                    ForceRedirectionAfterAddingToCart = settings.ForceRedirectionAfterAddingToCart,
                    CompareEnabled                    = _catalogSettings.CompareProductsEnabled,
                    WishlistEnabled                   = _services.Permissions.Authorize(Permissions.Cart.AccessWishlist),
                    BuyEnabled                        = !_catalogSettings.HideBuyButtonInLists,
                    ThumbSize                         = settings.ThumbnailSize,
                    ShowDiscountBadge                 = _catalogSettings.ShowDiscountSign,
                    ShowNewBadge                      = _catalogSettings.LabelAsNewForMaxDays.HasValue
                };

                if (products.Count == 0)
                {
                    // No products, stop here.
                    return(model);
                }

                // PERF!!
                var store                    = _services.StoreContext.CurrentStore;
                var customer                 = _services.WorkContext.CurrentCustomer;
                var currency                 = _services.WorkContext.WorkingCurrency;
                var language                 = _services.WorkContext.WorkingLanguage;
                var allowPrices              = _services.Permissions.Authorize(Permissions.Catalog.DisplayPrice);
                var allowShoppingCart        = _services.Permissions.Authorize(Permissions.Cart.AccessShoppingCart);
                var allowWishlist            = _services.Permissions.Authorize(Permissions.Cart.AccessWishlist);
                var taxDisplayType           = _services.WorkContext.GetTaxDisplayTypeFor(customer, store.Id);
                var cachedManufacturerModels = new Dictionary <int, ManufacturerOverviewModel>();
                var prefetchTranslations     = settings.PrefetchTranslations == true || (settings.PrefetchTranslations == null && _performanceSettings.AlwaysPrefetchTranslations);
                var prefetchSlugs            = settings.PrefetchUrlSlugs == true || (settings.PrefetchUrlSlugs == null && _performanceSettings.AlwaysPrefetchUrlSlugs);
                var allProductIds            = prefetchSlugs || prefetchTranslations?products.Select(x => x.Id).ToArray() : new int[0];

                //var productIds = products.Select(x => x.Id).ToArray();

                string taxInfo   = T(taxDisplayType == TaxDisplayType.IncludingTax ? "Tax.InclVAT" : "Tax.ExclVAT");
                var    legalInfo = "";

                var res = new Dictionary <string, LocalizedString>(StringComparer.OrdinalIgnoreCase)
                {
                    { "Products.CallForPrice", T("Products.CallForPrice") },
                    { "Products.PriceRangeFrom", T("Products.PriceRangeFrom") },
                    { "Media.Product.ImageLinkTitleFormat", T("Media.Product.ImageLinkTitleFormat") },
                    { "Media.Product.ImageAlternateTextFormat", T("Media.Product.ImageAlternateTextFormat") },
                    { "Products.DimensionsValue", T("Products.DimensionsValue") },
                    { "Common.AdditionalShippingSurcharge", T("Common.AdditionalShippingSurcharge") }
                };

                if (settings.MapLegalInfo)
                {
                    var shippingInfoUrl = _urlHelper.Topic("shippinginfo").ToString();
                    legalInfo = shippingInfoUrl.HasValue()
                        ? T("Tax.LegalInfoShort").Text.FormatInvariant(taxInfo, shippingInfoUrl)
                        : T("Tax.LegalInfoShort2").Text.FormatInvariant(taxInfo);
                }

                if (prefetchSlugs)
                {
                    _urlRecordService.PrefetchUrlRecords(nameof(Product), new[] { language.Id, 0 }, allProductIds);
                }

                if (prefetchTranslations)
                {
                    // Prefetch all delivery time translations
                    _localizedEntityService.PrefetchLocalizedProperties(nameof(DeliveryTime), language.Id, null);
                }

                using (var scope = new DbContextScope(ctx: _services.DbContext, autoCommit: false, validateOnSave: false))
                {
                    // Run in uncommitting scope, because pictures could be updated (IsNew property)
                    var batchContext = _dataExporter.Value.CreateProductExportContext(products, customer, null, 1, false);

                    if (settings.MapPrices)
                    {
                        batchContext.AppliedDiscounts.LoadAll();
                        batchContext.TierPrices.LoadAll();
                    }

                    if (settings.MapAttributes || settings.MapColorAttributes)
                    {
                        batchContext.Attributes.LoadAll();

                        if (prefetchTranslations)
                        {
                            // Prefetch all product attribute translations
                            PrefetchTranslations(
                                nameof(ProductAttribute),
                                language.Id,
                                batchContext.Attributes.SelectMany(x => x.Value).Select(x => x.ProductAttribute));

                            // Prefetch all variant attribute value translations
                            PrefetchTranslations(
                                nameof(ProductVariantAttributeValue),
                                language.Id,
                                batchContext.Attributes.SelectMany(x => x.Value).SelectMany(x => x.ProductVariantAttributeValues));
                        }
                    }

                    if (settings.MapManufacturers)
                    {
                        batchContext.ProductManufacturers.LoadAll();
                    }

                    if (settings.MapSpecificationAttributes)
                    {
                        batchContext.SpecificationAttributes.LoadAll();

                        if (prefetchTranslations)
                        {
                            // Prefetch all spec attribute option translations
                            PrefetchTranslations(
                                nameof(SpecificationAttributeOption),
                                language.Id,
                                batchContext.SpecificationAttributes.SelectMany(x => x.Value).Select(x => x.SpecificationAttributeOption));

                            // Prefetch all spec attribute translations
                            PrefetchTranslations(
                                nameof(SpecificationAttribute),
                                language.Id,
                                batchContext.SpecificationAttributes.SelectMany(x => x.Value).Select(x => x.SpecificationAttributeOption.SpecificationAttribute));
                        }
                    }

                    // If a size has been set in the view, we use it in priority
                    int thumbSize = model.ThumbSize ?? _mediaSettings.ProductThumbPictureSize;

                    var mapItemContext = new MapProductSummaryItemContext
                    {
                        BatchContext             = batchContext,
                        CachedManufacturerModels = cachedManufacturerModels,
                        Currency          = currency,
                        LegalInfo         = legalInfo,
                        Model             = model,
                        Resources         = res,
                        Settings          = settings,
                        Customer          = customer,
                        Store             = store,
                        AllowPrices       = allowPrices,
                        AllowShoppingCart = allowShoppingCart,
                        AllowWishlist     = allowWishlist,
                        TaxDisplayType    = taxDisplayType
                    };

                    if (settings.MapPictures)
                    {
                        var fileIds = products
                                      .Select(x => x.MainPictureId ?? 0)
                                      .Where(x => x != 0)
                                      .Distinct()
                                      .ToArray();

                        mapItemContext.MediaFiles = _mediaService.GetFilesByIds(fileIds).ToDictionarySafe(x => x.Id);
                    }

                    foreach (var product in products)
                    {
                        MapProductSummaryItem(product, mapItemContext);
                    }

                    _services.DisplayControl.AnnounceRange(products);

                    scope.Commit();

                    batchContext.Clear();

                    // don't show stuff without data at all
                    model.ShowDescription = model.ShowDescription && model.Items.Any(x => x.ShortDescription?.Value?.HasValue() == true);
                    model.ShowBrand       = model.ShowBrand && model.Items.Any(x => x.Manufacturer != null);

                    return(model);
                }
            }
        }
        public virtual async Task <ProductSummaryModel> MapProductSummaryModelAsync(IPagedList <Product> products, CatalogSearchResult sourceResult, ProductSummaryMappingSettings settings)
        {
            Guard.NotNull(products, nameof(products));

            if (settings == null)
            {
                settings = new ProductSummaryMappingSettings();
            }

            using (_services.Chronometer.Step("MapProductSummaryModel"))
            {
                var model = new ProductSummaryModel(products, sourceResult)
                {
                    ViewMode                          = settings.ViewMode,
                    GridColumnSpan                    = _catalogSettings.GridStyleListColumnSpan,
                    ShowSku                           = _catalogSettings.ShowProductSku,
                    ShowWeight                        = _catalogSettings.ShowWeight,
                    ShowDimensions                    = settings.MapDimensions,
                    ShowLegalInfo                     = settings.MapLegalInfo,
                    ShowDescription                   = settings.MapShortDescription,
                    ShowFullDescription               = settings.MapFullDescription,
                    ShowRatings                       = settings.MapReviews,
                    ShowPrice                         = settings.MapPrices,
                    ShowBasePrice                     = settings.MapPrices && _catalogSettings.ShowBasePriceInProductLists && settings.ViewMode != ProductSummaryViewMode.Mini,
                    ShowShippingSurcharge             = settings.MapPrices && settings.ViewMode != ProductSummaryViewMode.Mini,
                    ShowButtons                       = settings.ViewMode != ProductSummaryViewMode.Mini,
                    ShowBrand                         = settings.MapManufacturers,
                    ForceRedirectionAfterAddingToCart = settings.ForceRedirectionAfterAddingToCart,
                    CompareEnabled                    = _catalogSettings.CompareProductsEnabled,
                    WishlistEnabled                   = _services.Permissions.Authorize(Permissions.Cart.AccessWishlist),
                    BuyEnabled                        = !_catalogSettings.HideBuyButtonInLists,
                    ThumbSize                         = settings.ThumbnailSize,
                    ShowDiscountBadge                 = _catalogSettings.ShowDiscountSign,
                    ShowNewBadge                      = _catalogSettings.LabelAsNewForMaxDays.HasValue,
                    DeliveryTimesPresentation         = settings.DeliveryTimesPresentation,
                };

                if (products.Count == 0)
                {
                    // No products, stop here.
                    return(model);
                }

                using var scope = new DbContextScope(_db, retainConnection: true, deferCommit: true);

                // PERF!!
                var calculationOptions = _priceCalculationService.CreateDefaultOptions(true);
                var language           = calculationOptions.Language;
                var customer           = calculationOptions.Customer;
                var allowPrices        = await _services.Permissions.AuthorizeAsync(Permissions.Catalog.DisplayPrice);

                var allowShoppingCart = await _services.Permissions.AuthorizeAsync(Permissions.Cart.AccessShoppingCart);

                var allowWishlist = await _services.Permissions.AuthorizeAsync(Permissions.Cart.AccessWishlist);

                var cachedBrandModels    = new Dictionary <int, BrandOverviewModel>();
                var prefetchTranslations = settings.PrefetchTranslations == true || (settings.PrefetchTranslations == null && _performanceSettings.AlwaysPrefetchTranslations);
                var prefetchSlugs        = settings.PrefetchUrlSlugs == true || (settings.PrefetchUrlSlugs == null && _performanceSettings.AlwaysPrefetchUrlSlugs);
                var allProductIds        = prefetchSlugs || prefetchTranslations?products.Select(x => x.Id).ToArray() : Array.Empty <int>();

                //var productIds = products.Select(x => x.Id).ToArray();

                string taxInfo   = T(calculationOptions.TaxInclusive ? "Tax.InclVAT" : "Tax.ExclVAT");
                var    legalInfo = string.Empty;

                var res = new Dictionary <string, LocalizedString>(StringComparer.OrdinalIgnoreCase)
                {
                    { "Products.CallForPrice", T("Products.CallForPrice") },
                    { "Products.PriceRangeFrom", T("Products.PriceRangeFrom") },
                    { "Media.Product.ImageLinkTitleFormat", T("Media.Product.ImageLinkTitleFormat") },
                    { "Media.Product.ImageAlternateTextFormat", T("Media.Product.ImageAlternateTextFormat") },
                    { "Products.DimensionsValue", T("Products.DimensionsValue") },
                    { "Common.AdditionalShippingSurcharge", T("Common.AdditionalShippingSurcharge") }
                };

                if (settings.MapLegalInfo)
                {
                    var shippingInfoUrl = (await _urlHelper.TopicAsync("shippinginfo"));
                    legalInfo = shippingInfoUrl.HasValue()
                        ? T("Tax.LegalInfoShort", taxInfo, shippingInfoUrl)
                        : T("Tax.LegalInfoShort2", taxInfo);
                }

                if (prefetchSlugs)
                {
                    await _urlService.PrefetchUrlRecordsAsync(nameof(Product), new[] { language.Id, 0 }, allProductIds);
                }

                if (prefetchTranslations)
                {
                    // Prefetch all delivery time translations
                    await _localizedEntityService.PrefetchLocalizedPropertiesAsync(nameof(DeliveryTime), language.Id, null);
                }

                // Run in uncommitting scope, because pictures could be updated (IsNew property)
                var batchContext = _productService.CreateProductBatchContext(products, calculationOptions.Store, customer, false, true);

                if (settings.MapPrices)
                {
                    await batchContext.AppliedDiscounts.LoadAllAsync();

                    await batchContext.TierPrices.LoadAllAsync();
                }

                if (settings.MapAttributes || settings.MapColorAttributes)
                {
                    await batchContext.Attributes.LoadAllAsync();

                    if (prefetchTranslations)
                    {
                        // Prefetch all product attribute translations
                        await PrefetchTranslations(
                            nameof(ProductAttribute),
                            language.Id,
                            batchContext.Attributes.SelectMany(x => x.Value).Select(x => x.ProductAttribute));

                        // Prefetch all variant attribute value translations
                        await PrefetchTranslations(
                            nameof(ProductVariantAttributeValue),
                            language.Id,
                            batchContext.Attributes.SelectMany(x => x.Value).SelectMany(x => x.ProductVariantAttributeValues));
                    }
                }

                if (settings.MapManufacturers)
                {
                    await batchContext.ProductManufacturers.LoadAllAsync();
                }

                if (settings.MapSpecificationAttributes)
                {
                    await batchContext.SpecificationAttributes.LoadAllAsync();

                    if (prefetchTranslations)
                    {
                        // Prefetch all spec attribute option translations
                        await PrefetchTranslations(
                            nameof(SpecificationAttributeOption),
                            language.Id,
                            batchContext.SpecificationAttributes.SelectMany(x => x.Value).Select(x => x.SpecificationAttributeOption));

                        // Prefetch all spec attribute translations
                        await PrefetchTranslations(
                            nameof(SpecificationAttribute),
                            language.Id,
                            batchContext.SpecificationAttributes.SelectMany(x => x.Value).Select(x => x.SpecificationAttributeOption.SpecificationAttribute));
                    }
                }

                // If a size has been set in the view, we use it in priority
                int thumbSize = model.ThumbSize ?? _mediaSettings.ProductThumbPictureSize;

                calculationOptions.BatchContext = batchContext;

                // Don't perform discount limitation and coupon code check in list rendering as it can have heavy impact on performance.
                calculationOptions.CheckDiscountValidity = false;

                var mapItemContext = new MapProductSummaryItemContext
                {
                    BatchContext       = batchContext,
                    CalculationOptions = calculationOptions,
                    CachedBrandModels  = cachedBrandModels,
                    PrimaryCurrency    = _currencyService.PrimaryCurrency,
                    LegalInfo          = legalInfo,
                    Model                   = model,
                    Resources               = res,
                    MappingSettings         = settings,
                    AllowPrices             = allowPrices,
                    AllowShoppingCart       = allowShoppingCart,
                    AllowWishlist           = allowWishlist,
                    ShippingChargeTaxFormat = _currencyService.GetTaxFormat(priceIncludesTax: calculationOptions.TaxInclusive, target: PricingTarget.ShippingCharge, language: language),
                };

                if (settings.MapPictures)
                {
                    var fileIds = products
                                  .Select(x => x.MainPictureId ?? 0)
                                  .Where(x => x != 0)
                                  .Distinct()
                                  .ToArray();

                    mapItemContext.MediaFiles = (await _mediaService.GetFilesByIdsAsync(fileIds)).ToDictionarySafe(x => x.Id);
                }

                foreach (var product in products)
                {
                    await MapProductSummaryItem(product, mapItemContext);
                }

                _services.DisplayControl.AnnounceRange(products);

                await scope.CommitAsync();

                batchContext.Clear();

                // don't show stuff without data at all
                model.ShowDescription = model.ShowDescription && model.Items.Any(x => x.ShortDescription?.Value?.HasValue() == true);
                model.ShowBrand       = model.ShowBrand && model.Items.Any(x => x.Brand != null);

                return(model);
            }
        }