Skip to content

Commit

Permalink
Update PluginExtensions
Browse files Browse the repository at this point in the history
  • Loading branch information
KrzysztofPajak committed Aug 25, 2024
1 parent 355ebe8 commit 7b3c4c3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Web/Grand.Web.Admin/Controllers/PaymentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public async Task<IActionResult> Methods()
if (plugin != null)
{
tmp.ConfigurationUrl = plugin.ConfigurationUrl();
tmp.LogoUrl = pluginInfo.GetLogoUrl(_workContext);
tmp.LogoUrl = pluginInfo.GetLogoUrl(_workContext.CurrentHost.Url);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Web/Grand.Web.Admin/Controllers/PluginController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected virtual PluginModel PreparePluginModel(PluginInfo PluginInfo)
{
var pluginModel = PluginInfo.ToModel();
//logo
pluginModel.LogoUrl = PluginInfo.GetLogoUrl(workContext);
pluginModel.LogoUrl = PluginInfo.GetLogoUrl(workContext.CurrentHost.Url);

//configuration URLs
if (PluginInfo.Installed)
Expand Down
17 changes: 6 additions & 11 deletions src/Web/Grand.Web.Admin/Extensions/PluginExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
using Grand.Infrastructure;
using Grand.Infrastructure.Plugins;
using Grand.Infrastructure.Plugins;

namespace Grand.Web.Admin.Extensions;

public static class PluginExtensions
{
public static string GetLogoUrl(this PluginInfo pluginDescriptor, IWorkContext workContext)
public static string GetLogoUrl(this PluginInfo pluginDescriptor, string url)
{
ArgumentNullException.ThrowIfNull(pluginDescriptor);
ArgumentNullException.ThrowIfNull(workContext);

if (pluginDescriptor.OriginalAssemblyFile?.Directory == null) return null;
var storeLocation = workContext.CurrentHost.Url.TrimEnd('/');
var storeLocation = url.TrimEnd('/');
var pluginDirectory = pluginDescriptor.OriginalAssemblyFile.Directory;
var logoPluginJpg = Path.Combine(pluginDirectory.FullName, "logo.jpg");
if (File.Exists(logoPluginJpg))
return $"{storeLocation}/{pluginDirectory.Parent.Name}/{pluginDirectory.Name}/logo.jpg";
return $"{storeLocation}/{pluginDirectory.Parent?.Name}/{pluginDirectory.Name}/logo.jpg";
var logoPluginPng = Path.Combine(pluginDirectory.FullName, "logo.png");
if (File.Exists(logoPluginPng))
return $"{storeLocation}/{pluginDirectory.Parent.Name}/{pluginDirectory.Name}/logo.png";
return null;

return File.Exists(logoPluginPng) ? $"{storeLocation}/{pluginDirectory.Parent?.Name}/{pluginDirectory.Name}/logo.png" : null;
}
}

0 comments on commit 7b3c4c3

Please sign in to comment.