206 lines
7.0 KiB
C#
206 lines
7.0 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
|
using Microsoft.AspNetCore.Mvc.Routing;
|
|
using Nop.Core;
|
|
using Nop.Core.Domain.Catalog;
|
|
using Nop.Data;
|
|
using Nop.Plugin.AuctionPlugin.Components;
|
|
//using Nop.Plugin.Misc.AuctionPlugin.Components;
|
|
using Nop.Plugin.Widgets.AuctionPlugin.Components;
|
|
using Nop.Services.Catalog;
|
|
using Nop.Services.Cms;
|
|
using Nop.Services.Common;
|
|
using Nop.Services.Configuration;
|
|
using Nop.Services.Localization;
|
|
using Nop.Services.Plugins;
|
|
using Nop.Web.Framework.Infrastructure;
|
|
using Nop.Web.Framework.Menu;
|
|
|
|
namespace Nop.Plugin.Misc.AuctionPlugin
|
|
{
|
|
/// <summary>
|
|
/// Rename this file and change to the correct type
|
|
/// </summary>
|
|
public class AuctionPlugin : BasePlugin, IWidgetPlugin, IMiscPlugin, IAdminMenuPlugin
|
|
{
|
|
|
|
#region Fields
|
|
|
|
private readonly IWorkContext _context;
|
|
private readonly ILocalizationService _localizationService;
|
|
private readonly ISettingService _settingService;
|
|
private readonly IProductAttributeService _productAttributeService;
|
|
protected readonly IUrlHelperFactory _urlHelperFactory;
|
|
protected readonly IActionContextAccessor _actionContextAccessor;
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region Ctr
|
|
|
|
public AuctionPlugin(IWorkContext context,
|
|
ILocalizationService localizationService,
|
|
ISettingService settingService,
|
|
IProductAttributeService productAttributeService,
|
|
UrlHelperFactory urlHelperFactory,
|
|
IActionContextAccessor actionContextAccessor)
|
|
{
|
|
_context = context;
|
|
_localizationService = localizationService;
|
|
_settingService = settingService;
|
|
_productAttributeService = productAttributeService;
|
|
_urlHelperFactory = urlHelperFactory;
|
|
_actionContextAccessor = actionContextAccessor;
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
public override string GetConfigurationPageUrl()
|
|
{
|
|
return _urlHelperFactory.GetUrlHelper(_actionContextAccessor.ActionContext).RouteUrl(AuctionDefaults.ConfigurationRouteName);
|
|
}
|
|
|
|
public override async Task InstallAsync()
|
|
{
|
|
await _settingService.SaveSettingAsync(new AuctionSettings
|
|
{
|
|
SomeId = 1,
|
|
SomeText = "Hello",
|
|
});
|
|
|
|
var auctionAttribute = new ProductAttribute
|
|
{
|
|
Name = AuctionDefaults.AuctionAttributeName,
|
|
Description = "wether the product is on auction"
|
|
};
|
|
|
|
await _productAttributeService.InsertProductAttributeAsync(auctionAttribute);
|
|
|
|
//await _localizationService.AddOrUpdateLocaleResourceAsync(new Dictionary<string, string>
|
|
//{
|
|
// //add custom translation
|
|
//});
|
|
await base.InstallAsync();
|
|
}
|
|
|
|
public override async Task UninstallAsync()
|
|
{
|
|
var result = await _productAttributeService.GetAllProductAttributesAsync();
|
|
var thisAttribute = result.Where(x => x.Name == AuctionDefaults.AuctionAttributeName).FirstOrDefault();
|
|
await _productAttributeService.DeleteProductAttributeAsync(thisAttribute);
|
|
await base.UninstallAsync();
|
|
}
|
|
|
|
|
|
public bool HideInWidgetList => false;
|
|
|
|
public Type GetWidgetViewComponent(string widgetZone)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(widgetZone);
|
|
|
|
if (widgetZone.Equals(PublicWidgetZones.ProductDetailsInsideOverviewButtonsBefore))
|
|
{
|
|
return typeof(AuctionPublicViewComponent);
|
|
}
|
|
|
|
if (widgetZone.Equals(AdminWidgetZones.ProductDetailsBlock))
|
|
{
|
|
return typeof(AuctionAdminViewComponent);
|
|
}
|
|
|
|
if (widgetZone.Equals(PublicWidgetZones.HeaderAfter))
|
|
{
|
|
return typeof(LiveAnnouncementViewComponent);
|
|
}
|
|
|
|
return typeof(AuctionViewComponent);
|
|
}
|
|
|
|
public Task<IList<string>> GetWidgetZonesAsync()
|
|
{
|
|
return Task.FromResult<IList<string>>(new List<string>
|
|
{
|
|
PublicWidgetZones.ProductDetailsInsideOverviewButtonsBefore,
|
|
PublicWidgetZones.ProductDetailsBottom,
|
|
PublicWidgetZones.HeaderAfter
|
|
|
|
//AdminWidgetZones.OrderBillingAddressDetailsBottom,
|
|
//AdminWidgetZones.OrderShippingAddressDetailsBottom
|
|
});
|
|
}
|
|
|
|
public async Task ManageSiteMapAsync(SiteMapNode rootNode)
|
|
{
|
|
var liveAnnouncementPluginNode = rootNode.ChildNodes.FirstOrDefault(x => x.SystemName == "Auction");
|
|
|
|
if (liveAnnouncementPluginNode == null)
|
|
{
|
|
liveAnnouncementPluginNode = new SiteMapNode()
|
|
{
|
|
SystemName = "Auction",
|
|
Title = "Live Auction",
|
|
Visible = true,
|
|
IconClass = "fa-gear"
|
|
};
|
|
rootNode.ChildNodes.Add(liveAnnouncementPluginNode);
|
|
}
|
|
|
|
|
|
|
|
liveAnnouncementPluginNode.ChildNodes.Add(new SiteMapNode()
|
|
{
|
|
Title = await _localizationService.GetResourceAsync("Plugins.Configure"),
|
|
Visible = true,
|
|
IconClass = "fa-dot-circle-o",
|
|
Url = "~/Admin/AuctionPlugin/Configure"
|
|
|
|
});
|
|
|
|
liveAnnouncementPluginNode.ChildNodes.Add(new SiteMapNode()
|
|
{
|
|
Title = await _localizationService.GetResourceAsync("Misc.Auction"),
|
|
Visible = true,
|
|
IconClass = "fa-dot-circle-o",
|
|
Url = "~/Admin/AuctionPluginAdmin/GetAuctionViewModel"
|
|
});
|
|
|
|
liveAnnouncementPluginNode.ChildNodes.Add(new SiteMapNode()
|
|
{
|
|
Title = await _localizationService.GetResourceAsync("Misc.Announcement"),
|
|
Visible = true,
|
|
IconClass = "fa-dot-circle-o",
|
|
Url = "~/Admin/Announcement/GetAnnouncementViewModel"
|
|
|
|
});
|
|
|
|
|
|
|
|
liveAnnouncementPluginNode.ChildNodes.Add(new SiteMapNode()
|
|
{
|
|
Title = await _localizationService.GetResourceAsync("Misc.AnnouncementList"),
|
|
Visible = true,
|
|
IconClass = "fa-dot-circle-o",
|
|
Url = "~/Admin/Announcement/AnnouncementList"
|
|
});
|
|
|
|
liveAnnouncementPluginNode.ChildNodes.Add(new SiteMapNode()
|
|
{
|
|
Title = await _localizationService.GetResourceAsync("Misc.TestPage"),
|
|
Visible = true,
|
|
IconClass = "fa-dot-circle-o",
|
|
Url = "~/Admin/AuctionPluginAdmin/TestPage"
|
|
});
|
|
|
|
liveAnnouncementPluginNode.ChildNodes.Add(new SiteMapNode()
|
|
{
|
|
Title = await _localizationService.GetResourceAsync("Misc.SendBid"),
|
|
Visible = true,
|
|
IconClass = "fa-dot-circle-o",
|
|
Url = "~/Admin/Announcement/SendBidNotificationViewModel"
|
|
});
|
|
|
|
}
|
|
}
|
|
} |