Browse Source

Merge pull request #169 from EasyAbp/asc-displayorder

Make DisplayOrder effective and items sorted by ASC
pull/171/head
Super 4 years ago
committed by GitHub
parent
commit
93b0d6be65
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/ProductCategories/ProductCategoryAppService.cs
  2. 10
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Products/ProductAppService.cs
  3. 27
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Products/ProductViewAppService.cs

16
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/ProductCategories/ProductCategoryAppService.cs

@ -8,11 +8,12 @@ using Volo.Abp.Application.Services;
namespace EasyAbp.EShop.Products.ProductCategories namespace EasyAbp.EShop.Products.ProductCategories
{ {
public class ProductCategoryAppService : ReadOnlyAppService<ProductCategory, ProductCategoryDto, Guid, GetProductCategoryListDto>, public class ProductCategoryAppService :
ReadOnlyAppService<ProductCategory, ProductCategoryDto, Guid, GetProductCategoryListDto>,
IProductCategoryAppService IProductCategoryAppService
{ {
protected override string GetListPolicyName { get; set; } = ProductsPermissions.Products.Manage; protected override string GetListPolicyName { get; set; } = ProductsPermissions.Products.Manage;
private readonly IProductCategoryRepository _repository; private readonly IProductCategoryRepository _repository;
public ProductCategoryAppService(IProductCategoryRepository repository) : base(repository) public ProductCategoryAppService(IProductCategoryRepository repository) : base(repository)
@ -20,10 +21,11 @@ namespace EasyAbp.EShop.Products.ProductCategories
_repository = repository; _repository = repository;
} }
protected override async Task<IQueryable<ProductCategory>> CreateFilteredQueryAsync(GetProductCategoryListDto input) protected override async Task<IQueryable<ProductCategory>> CreateFilteredQueryAsync(
GetProductCategoryListDto input)
{ {
var queryable = await Repository.GetQueryableAsync(); var queryable = await Repository.GetQueryableAsync();
if (input.CategoryId.HasValue) if (input.CategoryId.HasValue)
{ {
queryable = queryable.Where(x => x.CategoryId == input.CategoryId); queryable = queryable.Where(x => x.CategoryId == input.CategoryId);
@ -37,6 +39,12 @@ namespace EasyAbp.EShop.Products.ProductCategories
return queryable; return queryable;
} }
protected override IQueryable<ProductCategory> ApplyDefaultSorting(IQueryable<ProductCategory> query)
{
return query.OrderBy(x => x.DisplayOrder)
.ThenBy(x => x.Id);
}
[RemoteService(false)] [RemoteService(false)]
public override Task<ProductCategoryDto> GetAsync(Guid id) public override Task<ProductCategoryDto> GetAsync(Guid id)
{ {

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

@ -64,6 +64,12 @@ namespace EasyAbp.EShop.Products.Products
.WhereIf(!input.ShowUnpublished, x => x.IsPublished); .WhereIf(!input.ShowUnpublished, x => x.IsPublished);
} }
protected override IQueryable<Product> ApplyDefaultSorting(IQueryable<Product> query)
{
return query.OrderBy(x => x.DisplayOrder)
.ThenBy(x => x.Id);
}
protected override Product MapToEntity(CreateUpdateProductDto createInput) protected override Product MapToEntity(CreateUpdateProductDto createInput)
{ {
var product = base.MapToEntity(createInput); var product = base.MapToEntity(createInput);
@ -481,12 +487,12 @@ namespace EasyAbp.EShop.Products.Products
protected virtual ProductDto SortAttributesAndOptions(ProductDto productDto) protected virtual ProductDto SortAttributesAndOptions(ProductDto productDto)
{ {
productDto.ProductAttributes = productDto.ProductAttributes.OrderByDescending(x => x.DisplayOrder).ToList(); productDto.ProductAttributes = productDto.ProductAttributes.OrderBy(x => x.DisplayOrder).ToList();
foreach (var productAttributeDto in productDto.ProductAttributes) foreach (var productAttributeDto in productDto.ProductAttributes)
{ {
productAttributeDto.ProductAttributeOptions = productAttributeDto.ProductAttributeOptions productAttributeDto.ProductAttributeOptions = productAttributeDto.ProductAttributeOptions
.OrderByDescending(x => x.DisplayOrder).ToList(); .OrderBy(x => x.DisplayOrder).ToList();
} }
return productDto; return productDto;

27
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Products/ProductViewAppService.cs

@ -15,7 +15,8 @@ using Volo.Abp.Uow;
namespace EasyAbp.EShop.Products.Products namespace EasyAbp.EShop.Products.Products
{ {
public class ProductViewAppService : MultiStoreReadOnlyAppService<ProductView, ProductViewDto, Guid, GetProductListInput>, public class ProductViewAppService :
MultiStoreReadOnlyAppService<ProductView, ProductViewDto, Guid, GetProductListInput>,
IProductViewAppService IProductViewAppService
{ {
protected override string GetPolicyName { get; set; } = null; protected override string GetPolicyName { get; set; } = null;
@ -27,7 +28,7 @@ namespace EasyAbp.EShop.Products.Products
private readonly IProductManager _productManager; private readonly IProductManager _productManager;
private readonly IProductRepository _productRepository; private readonly IProductRepository _productRepository;
private readonly IProductViewRepository _repository; private readonly IProductViewRepository _repository;
public ProductViewAppService( public ProductViewAppService(
IProductViewCacheKeyProvider productViewCacheKeyProvider, IProductViewCacheKeyProvider productViewCacheKeyProvider,
IDistributedCache<ProductViewCacheItem> cache, IDistributedCache<ProductViewCacheItem> cache,
@ -41,7 +42,7 @@ namespace EasyAbp.EShop.Products.Products
_productRepository = productRepository; _productRepository = productRepository;
_repository = repository; _repository = repository;
} }
protected override async Task<IQueryable<ProductView>> CreateFilteredQueryAsync(GetProductListInput input) protected override async Task<IQueryable<ProductView>> CreateFilteredQueryAsync(GetProductListInput input)
{ {
var query = input.CategoryId.HasValue var query = input.CategoryId.HasValue
@ -54,10 +55,16 @@ namespace EasyAbp.EShop.Products.Products
.WhereIf(!input.ShowUnpublished, x => x.IsPublished); .WhereIf(!input.ShowUnpublished, x => x.IsPublished);
} }
protected override IQueryable<ProductView> ApplyDefaultSorting(IQueryable<ProductView> query)
{
return query.OrderBy(x => x.DisplayOrder)
.ThenBy(x => x.Id);
}
public override async Task<PagedResultDto<ProductViewDto>> GetListAsync(GetProductListInput input) public override async Task<PagedResultDto<ProductViewDto>> GetListAsync(GetProductListInput input)
{ {
await CheckGetListPolicyAsync(); await CheckGetListPolicyAsync();
if (input.ShowHidden || input.ShowUnpublished) if (input.ShowHidden || input.ShowUnpublished)
{ {
await CheckMultiStorePolicyAsync(input.StoreId, ProductsPermissions.Products.Manage); await CheckMultiStorePolicyAsync(input.StoreId, ProductsPermissions.Products.Manage);
@ -67,7 +74,7 @@ namespace EasyAbp.EShop.Products.Products
{ {
await BuildStoreProductViewsAsync(input.StoreId); await BuildStoreProductViewsAsync(input.StoreId);
} }
var query = await CreateFilteredQueryAsync(input); var query = await CreateFilteredQueryAsync(input);
var totalCount = await AsyncExecuter.CountAsync(query); var totalCount = await AsyncExecuter.CountAsync(query);
@ -103,7 +110,7 @@ namespace EasyAbp.EShop.Products.Products
await BuildStoreProductViewsAsync(productView.StoreId); await BuildStoreProductViewsAsync(productView.StoreId);
productView = await GetEntityByIdAsync(id); productView = await GetEntityByIdAsync(id);
return await MapToGetOutputDtoAsync(productView); return await MapToGetOutputDtoAsync(productView);
} }
@ -120,7 +127,7 @@ namespace EasyAbp.EShop.Products.Products
var productView = ObjectMapper.Map<Product, ProductView>(product); var productView = ObjectMapper.Map<Product, ProductView>(product);
await FillPriceInfoWithRealPriceAsync(product, productView); await FillPriceInfoWithRealPriceAsync(product, productView);
await _repository.InsertAsync(productView); await _repository.InsertAsync(productView);
} }
@ -134,7 +141,7 @@ namespace EasyAbp.EShop.Products.Products
await SettingProvider.GetOrNullAsync(ProductsSettings.ProductView.CacheDurationSeconds))) await SettingProvider.GetOrNullAsync(ProductsSettings.ProductView.CacheDurationSeconds)))
}); });
} }
protected virtual async Task FillPriceInfoWithRealPriceAsync(Product product, ProductView productView) protected virtual async Task FillPriceInfoWithRealPriceAsync(Product product, ProductView productView)
{ {
if (product.ProductSkus.IsNullOrEmpty()) if (product.ProductSkus.IsNullOrEmpty())
@ -143,7 +150,7 @@ namespace EasyAbp.EShop.Products.Products
} }
decimal? min = null, max = null; decimal? min = null, max = null;
foreach (var productSku in product.ProductSkus) foreach (var productSku in product.ProductSkus)
{ {
var priceDataModel = await _productManager.GetRealPriceAsync(product, productSku); var priceDataModel = await _productManager.GetRealPriceAsync(product, productSku);
@ -162,4 +169,4 @@ namespace EasyAbp.EShop.Products.Products
productView.SetPrices(min, max); productView.SetPrices(min, max);
} }
} }
} }
Loading…
Cancel
Save