feat: update product service to support in-stock filtering and enhance top-selling product retrieval
Build and Deploy to Kubernetes / build-and-deploy (push) Failing after 23m11s
Build and Deploy to Kubernetes / build-and-deploy (push) Failing after 23m11s
- Modified `GetTopSellingAsync` methods in `ProductService` and `DiscountProductService` to include an optional `inStock` parameter for filtering products based on availability. - Introduced a constant for the top product count in `Index.razor.cs` to improve maintainability and readability. - Updated the product retrieval logic in `Index.razor.cs` to utilize the new in-stock filtering feature. These changes enhance the product listing functionality by allowing users to view only in-stock top-selling products, improving the overall shopping experience.
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DateTimeConverterCL" Version="1.0.0" />
|
||||
<!-- Replace all FrontOffice.BFF protobuf packages with CMS protobuf -->
|
||||
<PackageReference Include="Foursat.CMSMicroservice.Protobuf" Version="0.0.202" />
|
||||
<PackageReference Include="Foursat.CMSMicroservice.Protobuf" Version="0.0.204" />
|
||||
<!-- <ProjectReference Include="../../../CMS/src/CMSMicroservice.Protobuf/CMSMicroservice.Protobuf.csproj" />-->
|
||||
<PackageReference Include="MudBlazor" Version="8.14.0" />
|
||||
<PackageReference Include="Blazored.LocalStorage" Version="4.5.0" />
|
||||
|
||||
@@ -24,6 +24,8 @@ public partial class Index : IDisposable
|
||||
private LandingSettings? _settings;
|
||||
|
||||
// ── Top-selling product sections ──
|
||||
private const int LandingTopProductCount = 6;
|
||||
|
||||
private List<Product> _topRegularProducts = new();
|
||||
private List<DiscountProductCard> _topDiscountProducts = new();
|
||||
private bool _loadingTopProducts = true;
|
||||
@@ -65,9 +67,9 @@ public partial class Index : IDisposable
|
||||
PopulateFromSettings();
|
||||
_dataLoaded = true;
|
||||
|
||||
// Load top-selling products and blog posts in parallel
|
||||
var topRegTask = ProductService.GetTopSellingAsync(6);
|
||||
var topDiscTask = DiscountProductService.GetTopSellingAsync(6);
|
||||
// Load top-selling in-stock products and blog posts in parallel
|
||||
var topRegTask = ProductService.GetTopSellingAsync(LandingTopProductCount, inStock: true);
|
||||
var topDiscTask = DiscountProductService.GetTopSellingAsync(LandingTopProductCount, inStock: true);
|
||||
var featuredPostsTask = BlogPostService.GetFeaturedPostsAsync(2);
|
||||
|
||||
try
|
||||
|
||||
@@ -127,8 +127,8 @@ public class DiscountProductService
|
||||
}
|
||||
}
|
||||
|
||||
public Task<DiscountProductListResult> GetTopSellingAsync(int count = 6)
|
||||
=> GetProductsAsync(page: 1, pageSize: count, sortBy: "SaleCount desc");
|
||||
public Task<DiscountProductListResult> GetTopSellingAsync(int count = 6, bool? inStock = null)
|
||||
=> GetProductsAsync(page: 1, pageSize: count, sortBy: "SaleCount desc", inStock: inStock);
|
||||
|
||||
public async Task<DiscountProductDetail?> GetByIdAsync(long productId)
|
||||
{
|
||||
|
||||
@@ -71,12 +71,12 @@ public class ProductService
|
||||
return result.Products;
|
||||
}
|
||||
|
||||
public Task<ProductListResult> GetTopSellingAsync(int count = 6)
|
||||
=> GetProductsPagedAsync(sortBy: "SaleCount desc", page: 1, pageSize: count);
|
||||
public Task<ProductListResult> GetTopSellingAsync(int count = 6, bool? inStock = null)
|
||||
=> GetProductsPagedAsync(sortBy: "SaleCount desc", page: 1, pageSize: count, inStock: inStock);
|
||||
|
||||
public async Task<ProductListResult> GetProductsPagedAsync(
|
||||
string? query = null, long? categoryId = null, string? sortBy = null,
|
||||
int page = 1, int pageSize = 12)
|
||||
int page = 1, int pageSize = 12, bool? inStock = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -87,20 +87,25 @@ public class ProductService
|
||||
PageNumber = page,
|
||||
PageSize = pageSize
|
||||
},
|
||||
Filter = new GetAllProductsByFilterFilter
|
||||
{
|
||||
Title = query ?? string.Empty,
|
||||
Description = query ?? string.Empty,
|
||||
ShortInfomation = query ?? string.Empty,
|
||||
FullInformation = query ?? string.Empty
|
||||
}
|
||||
Filter = new GetAllProductsByFilterFilter()
|
||||
};
|
||||
|
||||
// فقط Title — CMS فیلترها را AND میزند؛ ارسال query در همه فیلدها جستجو را میشکند
|
||||
if (!string.IsNullOrWhiteSpace(query))
|
||||
{
|
||||
request.Filter.Title = query.Trim();
|
||||
}
|
||||
|
||||
if (categoryId is { } value)
|
||||
{
|
||||
request.Filter.CategoryId = value;
|
||||
}
|
||||
|
||||
if (inStock.HasValue)
|
||||
{
|
||||
request.Filter.InStock = inStock.Value;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(sortBy))
|
||||
{
|
||||
request.SortBy = sortBy;
|
||||
|
||||
Reference in New Issue
Block a user