Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Improvements - Admin panel - Product list - allow to search products by mark as new / show on homepage

KrzysztofPajak063cf0b7f609
diff --git a/src/Business/Grand.Business.Catalog/Interfaces/Products/IProductService.cs b/src/Business/Grand.Business.Catalog/Interfaces/Products/IProductService.cs
index 64e72aeb9..a77f95039 100644
--- a/src/Business/Grand.Business.Catalog/Interfaces/Products/IProductService.cs
+++ b/src/Business/Grand.Business.Catalog/Interfaces/Products/IProductService.cs
@@ -119,6 +119,7 @@ namespace Grand.Business.Catalog.Interfaces.Products
/// <param name="warehouseId">Warehouse identifier; "" to load all records</param>
/// <param name="productType">Product type; "" to load all records</param>
/// <param name="visibleIndividuallyOnly">A values indicating whether to load only products marked as "visible individually"; "false" to load all records; "true" to load "visible individually" only</param>
+ /// <param name="showOnHomePage">A value indicating whether loaded products show on homepage</param>
/// <param name="featuredProducts">A value indicating whether loaded products are marked as featured (relates only to categories and collections). 0 to load featured products only, 1 to load not featured products only, null to load all products</param>
/// <param name="priceMin">Minimum price; null to load all records</param>
/// <param name="priceMax">Maximum price; null to load all records</param>
@@ -150,6 +151,7 @@ namespace Grand.Business.Catalog.Interfaces.Products
ProductType? productType = null,
bool visibleIndividuallyOnly = false,
bool markedAsNewOnly = false,
+ bool? showOnHomePage = null,
bool? featuredProducts = null,
double? priceMin = null,
double? priceMax = null,
diff --git a/src/Business/Grand.Business.Catalog/Queries/Handlers/GetSearchProductsQueryHandler.cs b/src/Business/Grand.Business.Catalog/Queries/Handlers/GetSearchProductsQueryHandler.cs
index 500f6b84f..35c8fe76f 100644
--- a/src/Business/Grand.Business.Catalog/Queries/Handlers/GetSearchProductsQueryHandler.cs
+++ b/src/Business/Grand.Business.Catalog/Queries/Handlers/GetSearchProductsQueryHandler.cs
@@ -113,7 +113,10 @@ namespace Grand.Business.Catalog.Queries.Handlers
var productTypeId = (int)request.ProductType.Value;
query = query.Where(p => p.ProductTypeId == (ProductType)productTypeId);
}
-
+ if (request.ShowOnHomePage.HasValue)
+ {
+ query = query.Where(p => p.ShowOnHomePage == request.ShowOnHomePage.Value);
+ }
//The function 'CurrentUtcDateTime' is not supported by SQL Server Compact.
//That's why we pass the date value
var nowUtc = DateTime.UtcNow;
diff --git a/src/Business/Grand.Business.Catalog/Queries/Models/GetSearchProductsQuery.cs b/src/Business/Grand.Business.Catalog/Queries/Models/GetSearchProductsQuery.cs
index 7745b354e..ca826f94b 100644
--- a/src/Business/Grand.Business.Catalog/Queries/Models/GetSearchProductsQuery.cs
+++ b/src/Business/Grand.Business.Catalog/Queries/Models/GetSearchProductsQuery.cs
@@ -22,6 +22,7 @@ namespace Grand.Business.Catalog.Queries.Handlers
public ProductType? ProductType { get; set; } = null;
public bool VisibleIndividuallyOnly { get; set; } = false;
public bool MarkedAsNewOnly { get; set; } = false;
+ public bool? ShowOnHomePage { get; set; } = null;
public bool? FeaturedProducts { get; set; } = null;
public double? PriceMin { get; set; } = null;
public double? PriceMax { get; set; } = null;
diff --git a/src/Business/Grand.Business.Catalog/Services/Products/ProductService.cs b/src/Business/Grand.Business.Catalog/Services/Products/ProductService.cs
index dd4259f79..8e2467508 100644
--- a/src/Business/Grand.Business.Catalog/Services/Products/ProductService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Products/ProductService.cs
@@ -473,6 +473,7 @@ namespace Grand.Business.Catalog.Services.Products
ProductType? productType = null,
bool visibleIndividuallyOnly = false,
bool markedAsNewOnly = false,
+ bool? showOnHomePage = null,
bool? featuredProducts = null,
double? priceMin = null,
double? priceMax = null,
@@ -502,6 +503,7 @@ namespace Grand.Business.Catalog.Services.Products
ProductType = productType,
VisibleIndividuallyOnly = visibleIndividuallyOnly,
MarkedAsNewOnly = markedAsNewOnly,
+ ShowOnHomePage = showOnHomePage,
FeaturedProducts = featuredProducts,
PriceMin = priceMin,
PriceMax = priceMax,
diff --git a/src/Web/Grand.Web.Admin/Services/ProductViewModelService.cs b/src/Web/Grand.Web.Admin/Services/ProductViewModelService.cs
index 33b476622..8ad07d7de 100644
--- a/src/Web/Grand.Web.Admin/Services/ProductViewModelService.cs
+++ b/src/Web/Grand.Web.Admin/Services/ProductViewModelService.cs
@@ -759,9 +759,13 @@ namespace Grand.Web.Admin.Services
//0 - all (according to "ShowHidden" parameter)
//1 - published only
//2 - unpublished only
+ //3 - Show on homepage
+ //4 - mark as new
model.AvailablePublishedOptions.Add(new SelectListItem { Text = _translationService.GetResource("Admin.Catalog.Products.List.SearchPublished.All"), Value = " " });
model.AvailablePublishedOptions.Add(new SelectListItem { Text = _translationService.GetResource("Admin.Catalog.Products.List.SearchPublished.PublishedOnly"), Value = "1" });
model.AvailablePublishedOptions.Add(new SelectListItem { Text = _translationService.GetResource("Admin.Catalog.Products.List.SearchPublished.UnpublishedOnly"), Value = "2" });
+ model.AvailablePublishedOptions.Add(new SelectListItem { Text = _translationService.GetResource("Admin.Catalog.Products.List.SearchPublished.ShowOnHomePage"), Value = "3" });
+ model.AvailablePublishedOptions.Add(new SelectListItem { Text = _translationService.GetResource("Admin.Catalog.Products.List.SearchPublished.MarkAsNew"), Value = "4" });
return model;
}
@@ -792,6 +796,14 @@ namespace Grand.Web.Admin.Services
else if (model.SearchPublishedId == 2)
overridePublished = false;
+ bool? showOnHomePage = null;
+ if (model.SearchPublishedId == 3)
+ showOnHomePage = true;
+
+ bool markedAsNewOnly = false;
+ if (model.SearchPublishedId == 4)
+ markedAsNewOnly = true;
+
var products = (await _productService.SearchProducts(
categoryIds: categoryIds,
brandId: model.SearchBrandId,
@@ -804,7 +816,9 @@ namespace Grand.Web.Admin.Services
pageIndex: pageIndex - 1,
pageSize: pageSize,
showHidden: true,
- overridePublished: overridePublished
+ showOnHomePage: showOnHomePage,
+ overridePublished: overridePublished,
+ markedAsNewOnly: markedAsNewOnly
)).products;
var items = new List<ProductModel>();
diff --git a/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml b/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml
index a425696e5..67aed68e8 100644
--- a/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml
+++ b/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml
@@ -3267,9 +3267,15 @@
<Resource Name="Admin.Catalog.Products.List.SearchPublished.All">
<Value>All</Value>
</Resource>
+ <Resource Name="Admin.Catalog.Products.List.SearchPublished.MarkAsNew">
+ <Value>Mark as new</Value>
+ </Resource>
<Resource Name="Admin.Catalog.Products.List.SearchPublished.PublishedOnly">
<Value>Only published</Value>
</Resource>
+ <Resource Name="Admin.Catalog.Products.List.SearchPublished.ShowOnHomePage">
+ <Value>Show on homePage</Value>
+ </Resource>
<Resource Name="Admin.Catalog.Products.List.SearchPublished.UnpublishedOnly">
<Value>Only unpublished</Value>
</Resource>