Browse Source

Product purchasable check feature, close #18

pull/49/head
gdlcf88 6 years ago
parent
commit
eb75fb8a24
  1. 2
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Products/IProductAppService.cs
  2. 12
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Products/ProductAppService.cs
  3. 9
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain.Shared/EasyAbp/EShop/Products/Products/GetProductPurchasableStatusResult.cs
  4. 8
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain.Shared/EasyAbp/EShop/Products/Products/ProductPurchasableStatus.cs
  5. 13
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/IProductPurchasableStatusProvider.cs
  6. 13
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/ProductIsNotPurchasableException.cs
  7. 29
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/ProductPurchasableStatusProvider.cs

2
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Products/IProductAppService.cs

@ -23,5 +23,7 @@ namespace EasyAbp.EShop.Products.Products
Task<ProductDto> GetAsync(Guid id, Guid storeId); Task<ProductDto> GetAsync(Guid id, Guid storeId);
Task<ProductDto> DeleteSkuAsync(Guid productId, Guid productSkuId, Guid storeId); Task<ProductDto> DeleteSkuAsync(Guid productId, Guid productSkuId, Guid storeId);
Task<GetProductPurchasableStatusResult> GetPurchasableStatusAsync(Guid productId, Guid productSkuId, Guid storeId);
} }
} }

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

@ -24,17 +24,20 @@ namespace EasyAbp.EShop.Products.Products
protected override string GetPolicyName { get; set; } = null; protected override string GetPolicyName { get; set; } = null;
protected override string GetListPolicyName { get; set; } = null; protected override string GetListPolicyName { get; set; } = null;
private readonly IProductPurchasableStatusProvider _productPurchasableStatusProvider;
private readonly IAttributeOptionIdsSerializer _attributeOptionIdsSerializer; private readonly IAttributeOptionIdsSerializer _attributeOptionIdsSerializer;
private readonly IProductStoreRepository _productStoreRepository; private readonly IProductStoreRepository _productStoreRepository;
private readonly IProductCategoryRepository _productCategoryRepository; private readonly IProductCategoryRepository _productCategoryRepository;
private readonly IProductRepository _repository; private readonly IProductRepository _repository;
public ProductAppService( public ProductAppService(
IProductPurchasableStatusProvider productPurchasableStatusProvider,
IAttributeOptionIdsSerializer attributeOptionIdsSerializer, IAttributeOptionIdsSerializer attributeOptionIdsSerializer,
IProductStoreRepository productStoreRepository, IProductStoreRepository productStoreRepository,
IProductCategoryRepository productCategoryRepository, IProductCategoryRepository productCategoryRepository,
IProductRepository repository) : base(repository) IProductRepository repository) : base(repository)
{ {
_productPurchasableStatusProvider = productPurchasableStatusProvider;
_attributeOptionIdsSerializer = attributeOptionIdsSerializer; _attributeOptionIdsSerializer = attributeOptionIdsSerializer;
_productStoreRepository = productStoreRepository; _productStoreRepository = productStoreRepository;
_productCategoryRepository = productCategoryRepository; _productCategoryRepository = productCategoryRepository;
@ -351,6 +354,15 @@ namespace EasyAbp.EShop.Products.Products
return ObjectMapper.Map<Product, ProductDto>(product); return ObjectMapper.Map<Product, ProductDto>(product);
} }
public async Task<GetProductPurchasableStatusResult> GetPurchasableStatusAsync(Guid productId, Guid productSkuId, Guid storeId)
{
var product = await _repository.GetAsync(productId);
var productSku = product.ProductSkus.Single(sku => sku.Id == productSkuId);
return await _productPurchasableStatusProvider.GetPurchasableStatusAsync(product, productSku, storeId);
}
protected virtual async Task UpdateProductCategoriesAsync(Guid productId, IEnumerable<Guid> categoryIds) protected virtual async Task UpdateProductCategoriesAsync(Guid productId, IEnumerable<Guid> categoryIds)
{ {
await _productCategoryRepository.DeleteAsync(x => x.ProductId.Equals(productId)); await _productCategoryRepository.DeleteAsync(x => x.ProductId.Equals(productId));

9
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain.Shared/EasyAbp/EShop/Products/Products/GetProductPurchasableStatusResult.cs

@ -0,0 +1,9 @@
namespace EasyAbp.EShop.Products.Products
{
public class GetProductPurchasableStatusResult
{
public ProductPurchasableStatus PurchasableStatus { get; set; }
public string Reason { get; set; }
}
}

8
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain.Shared/EasyAbp/EShop/Products/Products/ProductPurchasableStatus.cs

@ -0,0 +1,8 @@
namespace EasyAbp.EShop.Products.Products
{
public enum ProductPurchasableStatus
{
CanBePurchased = 1,
CanNotBePurchased = 2
}
}

13
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/IProductPurchasableStatusProvider.cs

@ -0,0 +1,13 @@
using System;
using System.Threading.Tasks;
namespace EasyAbp.EShop.Products.Products
{
public interface IProductPurchasableStatusProvider
{
Task CheckPurchasableAsync(Product product, ProductSku productSku, Guid storeId);
Task<GetProductPurchasableStatusResult> GetPurchasableStatusAsync(Product product, ProductSku productSku,
Guid storeId);
}
}

13
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/ProductIsNotPurchasableException.cs

@ -0,0 +1,13 @@
using System;
using Volo.Abp;
namespace EasyAbp.EShop.Products.Products
{
public class ProductIsNotPurchasableException : BusinessException
{
public ProductIsNotPurchasableException(Guid id, string reason) : base(
message: $"Product {id} cannot be purchased, the reason is: {reason}")
{
}
}
}

29
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/ProductPurchasableStatusProvider.cs

@ -0,0 +1,29 @@
using System;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
namespace EasyAbp.EShop.Products.Products
{
public class ProductPurchasableStatusProvider : IProductPurchasableStatusProvider, ITransientDependency
{
public async Task CheckPurchasableAsync(Product product, ProductSku productSku, Guid storeId)
{
var result = await GetPurchasableStatusAsync(product, productSku, storeId);
if (result.PurchasableStatus != ProductPurchasableStatus.CanBePurchased)
{
throw new ProductIsNotPurchasableException(product.Id, result.Reason);
}
}
public async Task<GetProductPurchasableStatusResult> GetPurchasableStatusAsync(Product product, ProductSku productSku, Guid storeId)
{
// Todo: Determine whether the product can be purchased.
return new GetProductPurchasableStatusResult
{
PurchasableStatus = ProductPurchasableStatus.CanBePurchased,
Reason = null
};
}
}
}
Loading…
Cancel
Save