diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Products/ProductViewAppService.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Products/ProductViewAppService.cs index 1468f42f..a4ec2dd1 100644 --- a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Products/ProductViewAppService.cs +++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Products/ProductViewAppService.cs @@ -2,12 +2,14 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using EasyAbp.EShop.Products.Options; using EasyAbp.EShop.Products.Permissions; using EasyAbp.EShop.Products.Products.CacheItems; using EasyAbp.EShop.Products.Products.Dtos; using EasyAbp.EShop.Products.Settings; using EasyAbp.EShop.Stores.Stores; using Microsoft.Extensions.Caching.Distributed; +using Microsoft.Extensions.Options; using Volo.Abp.Application.Dtos; using Volo.Abp.Caching; using Volo.Abp.Uow; @@ -22,6 +24,7 @@ namespace EasyAbp.EShop.Products.Products protected override string GetListPolicyName { get; set; } = null; protected override string CrossStorePolicyName { get; set; } = ProductsPermissions.Products.CrossStore; + private readonly EShopProductsOptions _options; private readonly IProductViewCacheKeyProvider _productViewCacheKeyProvider; private readonly IDistributedCache _cache; private readonly IProductManager _productManager; @@ -29,12 +32,14 @@ namespace EasyAbp.EShop.Products.Products private readonly IProductViewRepository _repository; public ProductViewAppService( + IOptions options, IProductViewCacheKeyProvider productViewCacheKeyProvider, IDistributedCache cache, IProductManager productManager, IProductRepository productRepository, IProductViewRepository repository) : base(repository) { + _options = options.Value; _productViewCacheKeyProvider = productViewCacheKeyProvider; _cache = cache; _productManager = productManager; @@ -123,11 +128,13 @@ namespace EasyAbp.EShop.Products.Products await _repository.DeleteAsync(x => x.StoreId == storeId, true); + var productGroupDisplayNameMapping = await GetProductGroupDisplayNamesAsync(); var productViews = new Dictionary(); foreach (var product in products) { - var productView = ObjectMapper.Map(product); + productGroupDisplayNameMapping.TryGetValue(product.ProductGroupName, out var productGroupDisplayName); + var productView = new ProductView(product, productGroupDisplayName); productViews[product] = productView; } @@ -151,6 +158,12 @@ namespace EasyAbp.EShop.Products.Products } } + protected virtual Task> GetProductGroupDisplayNamesAsync() + { + return Task.FromResult(_options.Groups.GetConfigurationsDictionary() + .ToDictionary(x => x.Key, x => x.Value.DisplayName)); + } + protected virtual async Task GetCacheDurationOrNullAsync(List productViews, DateTime now) { diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/ProductsApplicationAutoMapperProfile.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/ProductsApplicationAutoMapperProfile.cs index ce85f7ff..f7cb401e 100644 --- a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/ProductsApplicationAutoMapperProfile.cs +++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/ProductsApplicationAutoMapperProfile.cs @@ -11,7 +11,6 @@ using EasyAbp.EShop.Products.ProductHistories; using EasyAbp.EShop.Products.ProductHistories.Dtos; using EasyAbp.EShop.Products.Products; using EasyAbp.EShop.Products.Products.Dtos; -using System.Linq; using Volo.Abp.AutoMapper; using Volo.Abp.DependencyInjection; @@ -46,7 +45,6 @@ namespace EasyAbp.EShop.Products CreateMap(); CreateMap(); CreateMap(); - CreateMap(MemberList.Destination); } } } diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/ProductView.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/ProductView.cs index a92291a5..41b72aa3 100644 --- a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/ProductView.cs +++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/ProductView.cs @@ -43,9 +43,9 @@ namespace EasyAbp.EShop.Products.Products public virtual string ProductGroupDisplayName { get; protected set; } - public virtual List ProductDiscounts { get; set; } + public virtual List ProductDiscounts { get; protected set; } - public virtual List OrderDiscountPreviews { get; set; } + public virtual List OrderDiscountPreviews { get; protected set; } public virtual decimal? MinimumPrice { get; protected set; } @@ -61,57 +61,28 @@ namespace EasyAbp.EShop.Products.Products { } - public ProductView( - Guid id, - Guid? tenantId, - Guid storeId, - string productGroupName, - Guid? productDetailId, - string uniqueName, - string displayName, - string overview, - InventoryStrategy inventoryStrategy, - string inventoryProviderName, - bool isPublished, - bool isStatic, - bool isHidden, - TimeSpan? paymentExpireIn, - string mediaResources, - int displayOrder, - string productGroupDisplayName, - List productDiscounts, - List orderDiscountPreviews, - decimal? minimumPrice, - decimal? maximumPrice, - decimal? minimumPriceWithoutDiscount, - decimal? maximumPriceWithoutDiscount, - long sold - ) : base(id) + public ProductView(Product product, string productGroupDisplayName) : base(product.Id) { - TenantId = tenantId; - StoreId = storeId; - ProductGroupName = productGroupName; - ProductDetailId = productDetailId; - UniqueName = uniqueName?.Trim(); - DisplayName = displayName; - Overview = overview; - InventoryStrategy = inventoryStrategy; - InventoryProviderName = inventoryProviderName; - IsPublished = isPublished; - IsStatic = isStatic; - IsHidden = isHidden; - PaymentExpireIn = paymentExpireIn; - MediaResources = mediaResources; - DisplayOrder = displayOrder; + TenantId = product.TenantId; + StoreId = product.StoreId; + ProductGroupName = product.ProductGroupName; + ProductDetailId = product.ProductDetailId; + UniqueName = product.UniqueName?.Trim(); + DisplayName = product.DisplayName; + Overview = product.Overview; + InventoryStrategy = product.InventoryStrategy; + InventoryProviderName = product.InventoryProviderName; + IsPublished = product.IsPublished; + IsStatic = product.IsStatic; + IsHidden = product.IsHidden; + PaymentExpireIn = product.PaymentExpireIn; + MediaResources = product.MediaResources; + DisplayOrder = product.DisplayOrder; ProductGroupDisplayName = productGroupDisplayName; - ProductDiscounts = productDiscounts ?? new List(); - OrderDiscountPreviews = orderDiscountPreviews ?? new List(); - MinimumPrice = minimumPrice; - MaximumPrice = maximumPrice; - MinimumPriceWithoutDiscount = minimumPriceWithoutDiscount; - MaximumPriceWithoutDiscount = maximumPriceWithoutDiscount; - Sold = sold; + + ProductDiscounts = new List(); + OrderDiscountPreviews = new List(); } public void SetSold(long sold)