Browse Source

Move GetDiscountedPriceAsync method to IProductManager

pull/87/head
gdlcf88 6 years ago
parent
commit
152cbb4d20
  1. 3
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Products/Dtos/ProductSkuDto.cs
  2. 5
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Products/ProductAppService.cs
  3. 11
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/IProductDiscountManager.cs
  4. 2
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/IProductManager.cs
  5. 22
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/ProductDiscountManager.cs
  6. 15
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/ProductManager.cs

3
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Products/Dtos/ProductSkuDto.cs

@ -19,9 +19,6 @@ namespace EasyAbp.EShop.Products.Products.Dtos
/// </summary> /// </summary>
public decimal Price { get; set; } public decimal Price { get; set; }
/// <summary>
/// Price from IProductDiscountManager
/// </summary>
public decimal DiscountedPrice { get; set; } public decimal DiscountedPrice { get; set; }
public int Inventory { get; set; } public int Inventory { get; set; }

5
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Products/ProductAppService.cs

@ -23,7 +23,6 @@ namespace EasyAbp.EShop.Products.Products
protected override string GetListPolicyName { get; set; } = null; protected override string GetListPolicyName { get; set; } = null;
private readonly IProductManager _productManager; private readonly IProductManager _productManager;
private readonly IProductDiscountManager _productDiscountManager;
private readonly IProductInventoryProvider _productInventoryProvider; private readonly IProductInventoryProvider _productInventoryProvider;
private readonly IAttributeOptionIdsSerializer _attributeOptionIdsSerializer; private readonly IAttributeOptionIdsSerializer _attributeOptionIdsSerializer;
private readonly IProductStoreRepository _productStoreRepository; private readonly IProductStoreRepository _productStoreRepository;
@ -31,14 +30,12 @@ namespace EasyAbp.EShop.Products.Products
public ProductAppService( public ProductAppService(
IProductManager productManager, IProductManager productManager,
IProductDiscountManager productDiscountManager,
IProductInventoryProvider productInventoryProvider, IProductInventoryProvider productInventoryProvider,
IAttributeOptionIdsSerializer attributeOptionIdsSerializer, IAttributeOptionIdsSerializer attributeOptionIdsSerializer,
IProductStoreRepository productStoreRepository, IProductStoreRepository productStoreRepository,
IProductRepository repository) : base(repository) IProductRepository repository) : base(repository)
{ {
_productManager = productManager; _productManager = productManager;
_productDiscountManager = productDiscountManager;
_productInventoryProvider = productInventoryProvider; _productInventoryProvider = productInventoryProvider;
_attributeOptionIdsSerializer = attributeOptionIdsSerializer; _attributeOptionIdsSerializer = attributeOptionIdsSerializer;
_productStoreRepository = productStoreRepository; _productStoreRepository = productStoreRepository;
@ -284,7 +281,7 @@ namespace EasyAbp.EShop.Products.Products
{ {
foreach (var productSkuDto in productDto.ProductSkus) foreach (var productSkuDto in productDto.ProductSkus)
{ {
productSkuDto.DiscountedPrice = await _productDiscountManager.GetDiscountedPriceAsync(product, productSkuDto.DiscountedPrice = await _productManager.GetDiscountedPriceAsync(product,
product.ProductSkus.Single(sku => sku.Id == productSkuDto.Id), storeId); product.ProductSkus.Single(sku => sku.Id == productSkuDto.Id), storeId);
} }

11
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/IProductDiscountManager.cs

@ -1,11 +0,0 @@
using System;
using System.Threading.Tasks;
using Volo.Abp.Domain.Services;
namespace EasyAbp.EShop.Products.Products
{
public interface IProductDiscountManager : IDomainService
{
Task<decimal> GetDiscountedPriceAsync(Product product, ProductSku productSku, Guid storeId);
}
}

2
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/IProductManager.cs

@ -28,5 +28,7 @@ namespace EasyAbp.EShop.Products.Products
Task<bool> TryIncreaseInventoryAsync(Product product, ProductSku productSku, Guid storeId, int quantity); Task<bool> TryIncreaseInventoryAsync(Product product, ProductSku productSku, Guid storeId, int quantity);
Task<bool> TryReduceInventoryAsync(Product product, ProductSku productSku, Guid storeId, int quantity); Task<bool> TryReduceInventoryAsync(Product product, ProductSku productSku, Guid storeId, int quantity);
Task<decimal> GetDiscountedPriceAsync(Product product, ProductSku productSku, Guid storeId);
} }
} }

22
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/ProductDiscountManager.cs

@ -1,22 +0,0 @@
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Domain.Services;
namespace EasyAbp.EShop.Products.Products
{
public class ProductDiscountManager : DomainService, IProductDiscountManager
{
public async Task<decimal> GetDiscountedPriceAsync(Product product, ProductSku productSku, Guid storeId)
{
var currentPrice = productSku.Price;
foreach (var provider in ServiceProvider.GetServices<IProductDiscountProvider>())
{
currentPrice = await provider.GetDiscountedPriceAsync(product, productSku, storeId, currentPrice);
}
return currentPrice;
}
}
}

15
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/ProductManager.cs

@ -3,9 +3,8 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using EasyAbp.EShop.Products.ProductCategories; using EasyAbp.EShop.Products.ProductCategories;
using EasyAbp.EShop.Products.ProductDetails;
using EasyAbp.EShop.Products.ProductStores; using EasyAbp.EShop.Products.ProductStores;
using Volo.Abp.Domain.Entities; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Domain.Services; using Volo.Abp.Domain.Services;
namespace EasyAbp.EShop.Products.Products namespace EasyAbp.EShop.Products.Products
@ -205,5 +204,17 @@ namespace EasyAbp.EShop.Products.Products
{ {
return await _productInventoryProvider.TryReduceInventoryAsync(product, productSku, storeId, quantity); return await _productInventoryProvider.TryReduceInventoryAsync(product, productSku, storeId, quantity);
} }
public virtual async Task<decimal> GetDiscountedPriceAsync(Product product, ProductSku productSku, Guid storeId)
{
var currentPrice = productSku.Price;
foreach (var provider in ServiceProvider.GetServices<IProductDiscountProvider>())
{
currentPrice = await provider.GetDiscountedPriceAsync(product, productSku, storeId, currentPrice);
}
return currentPrice;
}
} }
} }
Loading…
Cancel
Save