Browse Source

Fix the Product to ProductView mapping

pull/265/head
gdlcf88 3 years ago
parent
commit
7ef4fa8750
  1. 15
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Products/ProductViewAppService.cs
  2. 2
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/ProductsApplicationAutoMapperProfile.cs
  3. 71
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/ProductView.cs

15
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<ProductViewCacheItem> _cache;
private readonly IProductManager _productManager;
@ -29,12 +32,14 @@ namespace EasyAbp.EShop.Products.Products
private readonly IProductViewRepository _repository;
public ProductViewAppService(
IOptions<EShopProductsOptions> options,
IProductViewCacheKeyProvider productViewCacheKeyProvider,
IDistributedCache<ProductViewCacheItem> 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<Product, ProductView>();
foreach (var product in products)
{
var productView = ObjectMapper.Map<Product, ProductView>(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<Dictionary<string, string>> GetProductGroupDisplayNamesAsync()
{
return Task.FromResult(_options.Groups.GetConfigurationsDictionary()
.ToDictionary(x => x.Key, x => x.Value.DisplayName));
}
protected virtual async Task<TimeSpan?> GetCacheDurationOrNullAsync(List<ProductView> productViews,
DateTime now)
{

2
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<ProductHistory, ProductHistoryDto>();
CreateMap<ProductDetailHistory, ProductDetailHistoryDto>();
CreateMap<ProductView, ProductViewDto>();
CreateMap<Product, ProductView>(MemberList.Destination);
}
}
}

71
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<ProductDiscountInfoModel> ProductDiscounts { get; set; }
public virtual List<ProductDiscountInfoModel> ProductDiscounts { get; protected set; }
public virtual List<OrderDiscountPreviewInfoModel> OrderDiscountPreviews { get; set; }
public virtual List<OrderDiscountPreviewInfoModel> 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<ProductDiscountInfoModel> productDiscounts,
List<OrderDiscountPreviewInfoModel> 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<ProductDiscountInfoModel>();
OrderDiscountPreviews = orderDiscountPreviews ?? new List<OrderDiscountPreviewInfoModel>();
MinimumPrice = minimumPrice;
MaximumPrice = maximumPrice;
MinimumPriceWithoutDiscount = minimumPriceWithoutDiscount;
MaximumPriceWithoutDiscount = maximumPriceWithoutDiscount;
Sold = sold;
ProductDiscounts = new List<ProductDiscountInfoModel>();
OrderDiscountPreviews = new List<OrderDiscountPreviewInfoModel>();
}
public void SetSold(long sold)

Loading…
Cancel
Save