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.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
Minor improvements with GetProductOverviewHandler (call for price)
support56a2e4e6d2ad
diff --git a/src/Business/Grand.Business.Common/Services/Seo/SlugService.cs b/src/Business/Grand.Business.Common/Services/Seo/SlugService.csindex 90d342d81..2eab0d216 100644--- a/src/Business/Grand.Business.Common/Services/Seo/SlugService.cs+++ b/src/Business/Grand.Business.Common/Services/Seo/SlugService.cs@@ -160,8 +160,7 @@ namespace Grand.Business.Common.Services.Seo/// <returns>Found slug</returns>public virtual async Task<string> GetActiveSlug(string entityId, string entityName, string languageId){- var key = string.Format(CacheKey.URLEntity_ACTIVE_BY_ID_NAME_LANGUAGE_KEY, entityId, entityName,- languageId);+ var key = string.Format(CacheKey.URLEntity_ACTIVE_BY_ID_NAME_LANGUAGE_KEY, entityId, entityName, languageId);return await _cacheBase.GetAsync(key, async () =>{var source = _urlEntityRepository.Table;diff --git a/src/Web/Grand.Web/Features/Handlers/Products/GetProductDetailsPageHandler.cs b/src/Web/Grand.Web/Features/Handlers/Products/GetProductDetailsPageHandler.csindex 93814ccfa..613516a7e 100644--- a/src/Web/Grand.Web/Features/Handlers/Products/GetProductDetailsPageHandler.cs+++ b/src/Web/Grand.Web/Features/Handlers/Products/GetProductDetailsPageHandler.cs@@ -661,7 +661,8 @@ namespace Grand.Web.Features.Handlers.Products{var displayPrices = await _permissionService.Authorize(StandardPermission.DisplayPrices);var model = new ProductDetailsModel.ProductPriceModel {- ProductId = product.Id+ ProductId = product.Id,+ CallForPrice = product.CallForPrice};if (displayPrices){@@ -672,11 +673,7 @@ namespace Grand.Web.Features.Handlers.Products}else{- if (product.CallForPrice)- {- model.CallForPrice = true;- }- else+ if (!product.CallForPrice){var oldproductprice = await _taxService.GetProductPrice(product, product.OldPrice);var oldPriceBase = oldproductprice.productprice;diff --git a/src/Web/Grand.Web/Features/Handlers/Products/GetProductOverviewHandler.cs b/src/Web/Grand.Web/Features/Handlers/Products/GetProductOverviewHandler.csindex af30a3cc7..fe3d31245 100644--- a/src/Web/Grand.Web/Features/Handlers/Products/GetProductOverviewHandler.cs+++ b/src/Web/Grand.Web/Features/Handlers/Products/GetProductOverviewHandler.cs@@ -26,7 +26,6 @@ namespace Grand.Web.Features.Handlers.Products{private readonly IPermissionService _permissionService;private readonly IWorkContext _workContext;- private readonly ITranslationService _translationService;private readonly IProductService _productService;private readonly IBrandService _brandService;private readonly IPricingService _pricingService;@@ -43,7 +42,6 @@ namespace Grand.Web.Features.Handlers.Productspublic GetProductOverviewHandler(IPermissionService permissionService,IWorkContext workContext,- ITranslationService translationService,IProductService productService,IBrandService brandService,IPricingService priceCalculationService,@@ -59,7 +57,6 @@ namespace Grand.Web.Features.Handlers.Products{_permissionService = permissionService;_workContext = workContext;- _translationService = translationService;_productService = productService;_brandService = brandService;_pricingService = priceCalculationService;@@ -89,30 +86,12 @@ namespace Grand.Web.Features.Handlers.Productsvar pictureSize = request.ProductThumbPictureSize ?? _mediaSettings.ProductThumbPictureSize;var priceIncludesTax = _workContext.TaxDisplayType == TaxDisplayType.IncludingTax;- var res = new Dictionary<string, string> {- {- "Products.CallForPrice",- _translationService.GetResource("Products.CallForPrice", _workContext.WorkingLanguage.Id)- }, {- "Products.PriceRangeFrom",- _translationService.GetResource("Products.PriceRangeFrom", _workContext.WorkingLanguage.Id)- }, {- "Media.Product.ImageLinkTitleFormat",- _translationService.GetResource("Media.Product.ImageLinkTitleFormat",- _workContext.WorkingLanguage.Id)- }, {- "Media.Product.ImageAlternateTextFormat",- _translationService.GetResource("Media.Product.ImageAlternateTextFormat",- _workContext.WorkingLanguage.Id)- }- };-var tasks = new List<Task<ProductOverviewModel>>();foreach (var product in request.Products){tasks.Add(GetProductOverviewModel(product, request, displayPrices, enableShoppingCart, enableWishlist,- pictureSize, priceIncludesTax, res));+ pictureSize, priceIncludesTax));}var result = await Task.WhenAll(tasks);@@ -121,21 +100,20 @@ namespace Grand.Web.Features.Handlers.Productsprivate async Task<ProductOverviewModel> GetProductOverviewModel(Product product, GetProductOverview request,- bool displayPrices, bool enableShoppingCart, bool enableWishlist, int pictureSize, bool priceIncludesTax,- Dictionary<string, string> res)+ bool displayPrices, bool enableShoppingCart, bool enableWishlist, int pictureSize, bool priceIncludesTax){var model = await PrepareProductOverviewModel(product);//priceif (request.PreparePriceModel){- model.ProductPrice = await PreparePriceModel(product, res, request.ForceRedirectionAfterAddingToCart,+ model.ProductPrice = await PreparePriceModel(product, request.ForceRedirectionAfterAddingToCart,enableShoppingCart, displayPrices, enableWishlist, priceIncludesTax);}//pictureif (request.PreparePictureModel){- var pictureModels = await PreparePictureModel(product, model.Name, res, pictureSize);+ var pictureModels = await PreparePictureModel(product, model.Name, pictureSize);model.DefaultPictureModel = pictureModels.FirstOrDefault();if (pictureModels.Count > 1) model.SecondPictureModel = pictureModels.ElementAtOrDefault(1);}@@ -180,6 +158,8 @@ namespace Grand.Web.Features.Handlers.ProductsLowStock = product.LowStock,ShowSku = _catalogSettings.ShowSkuOnCatalogPages,TaxDisplayType = _workContext.TaxDisplayType,+ Interval = product.Interval,+ IntervalUnitId = product.IntervalUnitId,EndTime = product.AvailableEndDateTimeUtc,EndTimeLocalTime = product.AvailableEndDateTimeUtc.HasValue? _dateTimeService.ConvertToUserTime(product.AvailableEndDateTimeUtc.Value, DateTimeKind.Utc)@@ -196,14 +176,14 @@ namespace Grand.Web.Features.Handlers.Products}private async Task<ProductOverviewModel.ProductPriceModel> PreparePriceModel(Product product,- IReadOnlyDictionary<string, string> res,bool forceRedirectionAfterAddingToCart, bool enableShoppingCart, bool displayPrices, bool enableWishlist,bool priceIncludesTax){#region Prepare product pricevar priceModel = new ProductOverviewModel.ProductPriceModel {- ForceRedirectionAfterAddingToCart = forceRedirectionAfterAddingToCart+ ForceRedirectionAfterAddingToCart = forceRedirectionAfterAddingToCart,+ CallForPrice = product.CallForPrice};switch (product.ProductTypeId)@@ -258,7 +238,7 @@ namespace Grand.Web.Features.Handlers.Productsif (minPriceProduct.CallForPrice){priceModel.OldPrice = null;- priceModel.Price = res["Products.CallForPrice"];+ priceModel.Price = "";}else{@@ -269,8 +249,7 @@ namespace Grand.Web.Features.Handlers.Products.productprice;priceModel.OldPrice = null;- priceModel.Price = string.Format(res["Products.PriceRangeFrom"],- _priceFormatter.FormatPrice(finalPrice, _workContext.WorkingCurrency));+ priceModel.Price = _priceFormatter.FormatPrice(finalPrice, _workContext.WorkingCurrency);priceModel.PriceValue = finalPrice;//PAngV base price (used in Germany)@@ -356,7 +335,7 @@ namespace Grand.Web.Features.Handlers.Products{//call for pricepriceModel.OldPrice = null;- priceModel.Price = res["Products.CallForPrice"];+ priceModel.Price = "";}else{@@ -399,8 +378,7 @@ namespace Grand.Web.Features.Handlers.Productsif (displayFromMessage){priceModel.OldPrice = null;- priceModel.Price = string.Format(res["Products.PriceRangeFrom"],- _priceFormatter.FormatPrice(finalPrice, _workContext.WorkingCurrency));+ priceModel.Price = _priceFormatter.FormatPrice(finalPrice, _workContext.WorkingCurrency);priceModel.PriceValue = finalPrice;}else@@ -419,16 +397,6 @@ namespace Grand.Web.Features.Handlers.ProductspriceModel.PriceValue = finalPrice;}}-- if (product.ProductTypeId == ProductType.Reservation)- {- //rental product- if(!string.IsNullOrEmpty(priceModel.OldPrice))- priceModel.OldPrice = string.Format(_translationService.GetResource(product.ResourceReservationProductPeriod()), priceModel.OldPrice, product.Interval);-- priceModel.Price = string.Format(_translationService.GetResource(product.ResourceReservationProductPeriod()), priceModel.Price, product.Interval);- }-//PAngV base price (used in Germany)if (product.BasepriceEnabled)priceModel.BasePricePAngV = await _mediator.Send(new GetFormatBasePrice {@@ -455,8 +423,7 @@ namespace Grand.Web.Features.Handlers.Products#endregion}- private async Task<IList<PictureModel>> PreparePictureModel(Product product, string name,- IReadOnlyDictionary<string, string> res, int pictureSize)+ private async Task<IList<PictureModel>> PreparePictureModel(Product product, string name, int pictureSize){#region Prepare product picture@@ -480,14 +447,14 @@ namespace Grand.Web.Features.Handlers.Productspicture != null && !string.IsNullOrEmpty(picture.GetTranslation(x => x.TitleAttribute,_workContext.WorkingLanguage.Id))? picture.GetTranslation(x => x.TitleAttribute, _workContext.WorkingLanguage.Id)- : string.Format(res["Media.Product.ImageLinkTitleFormat"], name),+ : name,//"alt" attributeAlternateText =picture != null &&!string.IsNullOrEmpty(picture.GetTranslation(x => x.AltAttribute,_workContext.WorkingLanguage.Id))? picture.GetTranslation(x => x.AltAttribute, _workContext.WorkingLanguage.Id)- : string.Format(res["Media.Product.ImageAlternateTextFormat"], name)+ : name};return pictureModel;diff --git a/src/Web/Grand.Web/Models/Catalog/ProductOverviewModel.cs b/src/Web/Grand.Web/Models/Catalog/ProductOverviewModel.csindex b26b73193..d8a7ce7c0 100644--- a/src/Web/Grand.Web/Models/Catalog/ProductOverviewModel.cs+++ b/src/Web/Grand.Web/Models/Catalog/ProductOverviewModel.cs@@ -27,7 +27,11 @@ namespace Grand.Web.Models.Catalogpublic DateTime? EndTime { get; set; }public DateTime? EndTimeLocalTime { get; set; }public TaxDisplayType TaxDisplayType { get; set; }-++ public int Interval { get; set; }++ public IntervalUnit IntervalUnitId { get; set; }+//pricepublic ProductPriceModel ProductPrice { get; set; } = new();@@ -52,6 +56,7 @@ namespace Grand.Web.Models.Catalogpublic double OldPriceValue { get; set; }public string CatalogPrice { get; set; }public string Price { get; set; }+ public bool CallForPrice { get; set; }public double PriceValue { get; set; }public bool PriceIncludesTax { get; set; }public string StartPrice { get; set; }diff --git a/src/Web/Grand.Web/Views/Catalog/Partials/CatalogProductGridView.cshtml b/src/Web/Grand.Web/Views/Catalog/Partials/CatalogProductGridView.cshtmlindex 9a1f51cd5..e1c6e4d16 100644--- a/src/Web/Grand.Web/Views/Catalog/Partials/CatalogProductGridView.cshtml+++ b/src/Web/Grand.Web/Views/Catalog/Partials/CatalogProductGridView.cshtml@@ -67,6 +67,9 @@<template v-if="Model.ProductType != 25"><div class="actual-price price">{{Model.ProductPrice.Price}}+ <template v-if="Model.ProductPrice.CallForPrice">+ @Loc["Products.CallForPrice"]+ </template></div></template><template v-else>diff --git a/src/Web/Grand.Web/Views/Catalog/Partials/CatalogProductListView.cshtml b/src/Web/Grand.Web/Views/Catalog/Partials/CatalogProductListView.cshtmlindex 6b6a39ae0..153958a40 100644--- a/src/Web/Grand.Web/Views/Catalog/Partials/CatalogProductListView.cshtml+++ b/src/Web/Grand.Web/Views/Catalog/Partials/CatalogProductListView.cshtml@@ -68,6 +68,9 @@<template v-if="Model.ProductType != 25"><div class="actual-price price">{{Model.ProductPrice.Price}}+ <template v-if="Model.ProductPrice.CallForPrice">+ @Loc["Products.CallForPrice"]+ </template></div></template><template v-else>diff --git a/src/Web/Grand.Web/Views/Shared/Partials/CatalogProductView.cshtml b/src/Web/Grand.Web/Views/Shared/Partials/CatalogProductView.cshtmlindex 5aeb5e6d3..3ca0ae5da 100644--- a/src/Web/Grand.Web/Views/Shared/Partials/CatalogProductView.cshtml+++ b/src/Web/Grand.Web/Views/Shared/Partials/CatalogProductView.cshtml@@ -97,6 +97,10 @@{<div class="actual-price price">@Model.ProductPrice.Price+ @if (Model.ProductPrice.CallForPrice)+ {+ @Loc["Products.CallForPrice"]+ }</div>}else