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.

Add BrandName to ProductOverviewModel

supportbe181a4b0b62
diff --git a/src/Web/Grand.Web/Features/Handlers/Products/GetProductOverviewHandler.cs b/src/Web/Grand.Web/Features/Handlers/Products/GetProductOverviewHandler.cs
index 06e3debe4..874b7b507 100644
--- a/src/Web/Grand.Web/Features/Handlers/Products/GetProductOverviewHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/Products/GetProductOverviewHandler.cs
@@ -19,6 +19,7 @@ using MediatR;
using System.Diagnostics;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
+using Grand.Business.Core.Interfaces.Catalog.Brands;
namespace Grand.Web.Features.Handlers.Products
{
@@ -28,6 +29,7 @@ namespace Grand.Web.Features.Handlers.Products
private readonly IWorkContext _workContext;
private readonly ITranslationService _translationService;
private readonly IProductService _productService;
+ private readonly IBrandService _brandService;
private readonly IPricingService _pricingService;
private readonly ITaxService _taxService;
private readonly ICurrencyService _currencyService;
@@ -45,6 +47,7 @@ namespace Grand.Web.Features.Handlers.Products
IWorkContext workContext,
ITranslationService translationService,
IProductService productService,
+ IBrandService brandService,
IPricingService priceCalculationService,
ITaxService taxService,
ICurrencyService currencyService,
@@ -61,6 +64,7 @@ namespace Grand.Web.Features.Handlers.Products
_workContext = workContext;
_translationService = translationService;
_productService = productService;
+ _brandService = brandService;
_pricingService = priceCalculationService;
_taxService = taxService;
_currencyService = currencyService;
@@ -107,7 +111,7 @@ namespace Grand.Web.Features.Handlers.Products
private async Task<ProductOverviewModel> GetProductOverviewModel(Product product, GetProductOverview request,
bool displayPrices, bool enableShoppingCart, bool enableWishlist, int pictureSize, bool priceIncludesTax, Dictionary<string, string> res)
{
- var model = PrepareProductOverviewModel(product);
+ var model = await PrepareProductOverviewModel(product);
//price
if (request.PreparePriceModel)
{
@@ -138,11 +142,10 @@ namespace Grand.Web.Features.Handlers.Products
return model;
}
- private ProductOverviewModel PrepareProductOverviewModel(Product product)
+ private async Task<ProductOverviewModel> PrepareProductOverviewModel(Product product)
{
var sename = product.GetSeName(_workContext.WorkingLanguage.Id);
- var model = new ProductOverviewModel
- {
+ var model = new ProductOverviewModel {
Id = product.Id,
Name = product.GetTranslation(x => x.Name, _workContext.WorkingLanguage.Id),
ShortDescription = product.GetTranslation(x => x.ShortDescription, _workContext.WorkingLanguage.Id),
@@ -154,6 +157,7 @@ namespace Grand.Web.Features.Handlers.Products
Gtin = product.Gtin,
Flag = product.Flag,
Mpn = product.Mpn,
+ BrandName = string.IsNullOrEmpty(product.BrandId) ? "" : (await _brandService.GetBrandById(product.BrandId))?.GetTranslation(x => x.Name, _workContext.WorkingLanguage.Id),
IsFreeShipping = product.IsFreeShipping,
LowStock = product.LowStock,
ShowSku = _catalogSettings.ShowSkuOnCatalogPages,
diff --git a/src/Web/Grand.Web/Models/Catalog/ProductOverviewModel.cs b/src/Web/Grand.Web/Models/Catalog/ProductOverviewModel.cs
index 49ed50761..68d0da840 100644
--- a/src/Web/Grand.Web/Models/Catalog/ProductOverviewModel.cs
+++ b/src/Web/Grand.Web/Models/Catalog/ProductOverviewModel.cs
@@ -28,6 +28,7 @@ namespace Grand.Web.Models.Catalog
public string Flag { get; set; }
public string Gtin { get; set; }
public string Mpn { get; set; }
+ public string BrandName { get; set; }
public bool IsFreeShipping { get; set; }
public bool ShowSku { get; set; }
public bool ShowQty { get; set; }