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
Fix for tenants - Could not find a part of the path for images, firebase, files #90
KrzysztofPajakf15407a09a1b
diff --git a/src/Business/Grand.Business.Common/Services/Pdf/WkPdfService.cs b/src/Business/Grand.Business.Common/Services/Pdf/WkPdfService.csindex 236a4b9dc..8759f1c06 100644--- a/src/Business/Grand.Business.Common/Services/Pdf/WkPdfService.cs+++ b/src/Business/Grand.Business.Common/Services/Pdf/WkPdfService.cs@@ -50,7 +50,7 @@ namespace Grand.Business.Common.Services.Pdf{PageSize = Wkhtmltopdf.NetCore.Options.Size.A4,PageMargins = new Wkhtmltopdf.NetCore.Options.Margins() { Bottom = 10, Left = 10, Right = 10, Top = 10 },- FooterHtml = CommonPath.WebMapPath(_orderFooter)+ FooterHtml = CommonPath.WebHostMapPath(_orderFooter)});var html = await _viewRenderService.RenderToStringAsync<(IList<Order>,string)>(_orderTemaplate, new (orders, vendorId));@@ -92,7 +92,7 @@ namespace Grand.Business.Common.Services.Pdf{PageSize = Wkhtmltopdf.NetCore.Options.Size.A4,PageMargins = new Wkhtmltopdf.NetCore.Options.Margins() { Bottom = 10, Left = 10, Right = 10, Top = 10 },- FooterHtml = CommonPath.WebMapPath(_shipmentFooter)+ FooterHtml = CommonPath.WebHostMapPath(_shipmentFooter)});var html = await _viewRenderService.RenderToStringAsync<IList<Shipment>>(_shipmentsTemaplate, shipments);diff --git a/src/Business/Grand.Business.Storage/Services/PictureService.cs b/src/Business/Grand.Business.Storage/Services/PictureService.csindex 2bb94d179..cfb7a3689 100644--- a/src/Business/Grand.Business.Storage/Services/PictureService.cs+++ b/src/Business/Grand.Business.Storage/Services/PictureService.cs@@ -45,6 +45,9 @@ namespace Grand.Business.Storage.Services//Used for thumb imagesprivate readonly string _thumbPath;+ //path to the no image file+ private readonly string _path_no_image = "assets/images/no-image.png";+#endregion#region Ctor@@ -282,7 +285,7 @@ namespace Grand.Business.Storage.Servicesvar filePath = await GetPicturePhysicalPath(_mediaSettings.DefaultImageName);if (string.IsNullOrEmpty(filePath)){- return "";+ return _path_no_image;}if (targetSize == 0){diff --git a/src/Core/Grand.SharedKernel/Extensions/CommonPath.cs b/src/Core/Grand.SharedKernel/Extensions/CommonPath.csindex 3092c8532..491cf9fac 100644--- a/src/Core/Grand.SharedKernel/Extensions/CommonPath.cs+++ b/src/Core/Grand.SharedKernel/Extensions/CommonPath.cs@@ -108,10 +108,10 @@ namespace Grand.SharedKernel.Extensionspublic static string BaseDirectory { get; set; }/// <summary>- /// Maps a virtual path to a physical disk path.+ /// Maps a virtual path to a physical disk path (for tenants)./// </summary>/// <param name="path">The path to map. E.g. "~/bin"</param>- /// <returns>The physical path. E.g. "c:\inetpub\wwwroot\bin"</returns>+ /// <returns>The physical path. E.g. "c:\inetpub\wwwroot\"</returns>public static string WebMapPath(string path){path = path.Replace("~/", "").TrimStart('/');@@ -129,6 +129,17 @@ namespace Grand.SharedKernel.Extensions}}+ /// <summary>+ /// Maps a virtual path to a physical disk path. (not for tenants)+ /// </summary>+ /// <param name="path">The path to map. E.g. "~/bin"</param>+ /// <returns>The physical path. E.g. "c:\inetpub\wwwroot\"</returns>+ public static string WebHostMapPath(string path)+ {+ path = path.Replace("~/", "").TrimStart('/');+ return Path.Combine(WebHostEnvironment, path);+ }+/// <summary>/// Gets or sets web application content files/// </summary>diff --git a/src/Web/Grand.Web.Admin/Controllers/SettingController.cs b/src/Web/Grand.Web.Admin/Controllers/SettingController.csindex d795ecbea..4e88cdf51 100644--- a/src/Web/Grand.Web.Admin/Controllers/SettingController.cs+++ b/src/Web/Grand.Web.Admin/Controllers/SettingController.cs@@ -1071,11 +1071,22 @@ namespace Grand.Web.Admin.Controllers//now clear cacheawait ClearCache();+ //save to file+ SavePushNotificationsToFile(model);++ Success(_translationService.GetResource("Admin.Configuration.Updated"));+ return await PushNotifications();+ }++ private void SavePushNotificationsToFile(ConfigurationModel model)+ {//edit js file needed by firebase- var jsFilePath = CommonPath.WebMapPath("firebase-messaging-sw.js");- if (System.IO.File.Exists(jsFilePath))+ var filename = "firebase-messaging-sw.js";+ var oryginalFilePath = CommonPath.WebHostMapPath(filename);+ var savedFilePath = CommonPath.WebMapPath(filename);+ if (System.IO.File.Exists(oryginalFilePath)){- string[] lines = System.IO.File.ReadAllLines(jsFilePath);+ string[] lines = System.IO.File.ReadAllLines(oryginalFilePath);int i = 0;foreach (var line in lines)@@ -1117,14 +1128,12 @@ namespace Grand.Web.Admin.Controllersi++;}-- System.IO.File.WriteAllLines(jsFilePath, lines);+ System.IO.File.WriteAllLines(savedFilePath, lines);}+ else+ throw new ArgumentNullException($"{oryginalFilePath} not exist");- Success(_translationService.GetResource("Admin.Configuration.Updated"));- return await PushNotifications();}-public IActionResult AdminSearch(){var settings = _settingService.LoadSetting<AdminSearchSettings>();diff --git a/src/Web/Grand.Web.Admin/Services/LanguageViewModelService.cs b/src/Web/Grand.Web.Admin/Services/LanguageViewModelService.csindex a24d4b9ce..fbaf5fb06 100644--- a/src/Web/Grand.Web.Admin/Services/LanguageViewModelService.cs+++ b/src/Web/Grand.Web.Admin/Services/LanguageViewModelService.cs@@ -44,7 +44,7 @@ namespace Grand.Web.Admin.Servicesthrow new ArgumentNullException(nameof(model));model.FlagFileNames = Directory- .EnumerateFiles(CommonPath.WebMapPath("/assets/images/flags/"), "*.png", SearchOption.TopDirectoryOnly)+ .EnumerateFiles(CommonPath.WebHostMapPath("/assets/images/flags/"), "*.png", SearchOption.TopDirectoryOnly).Select(Path.GetFileName).ToList();}