diff --git a/BaseBaroquePlugin.cs b/BaseBaroquePlugin.cs index db09d09..d14ab41 100644 --- a/BaseBaroquePlugin.cs +++ b/BaseBaroquePlugin.cs @@ -30,156 +30,131 @@ namespace Nop.Plugin.Widgets.qBoSlider /// public abstract class BaseBaroquePlugin : BasePlugin { - #region Fields + #region Fields - private readonly ILanguageService _languageService; - private readonly ILocalizationService _localizationService; + private readonly ILanguageService _languageService; + private readonly ILocalizationService _localizationService; - private readonly FileInfo _originalAssemblyFile; + #endregion - #endregion + #region Properties - #region Constructor + public FileInfo _originalAssemblyFile { get; private set; } - public BaseBaroquePlugin() - { - //get plugin descriptor - var pluginsInfo = Singleton.Instance; - var descriptor = pluginsInfo.PluginDescriptors.FirstOrDefault(x => x.PluginType == this.GetType()); - //intialize varialbes - this._localizationService = EngineContext.Current.Resolve(); - this._languageService = EngineContext.Current.Resolve(); - this._originalAssemblyFile = new FileInfo(descriptor.OriginalAssemblyFile); - } + #endregion - #endregion + #region Constructor - #region Utilites + public BaseBaroquePlugin() + { + //get plugin descriptor + var pluginsInfo = Singleton.Instance; + var descriptor = pluginsInfo.PluginDescriptors.FirstOrDefault(x => x.PluginType == this.GetType()); + //intialize varialbes + this._localizationService = EngineContext.Current.Resolve(); + this._languageService = EngineContext.Current.Resolve(); + this._originalAssemblyFile = new FileInfo(descriptor.OriginalAssemblyFile); + } - /// - /// Generate localization file path by language culture - /// - /// Language culture. For example 'en-US' - /// Localization Xml file path - protected string GenerateLocalizationXmlFilePathByCulture(string culture = "en-US") - { - string fileName = string.Format("localization.{0}.xml", culture); - string contentDirectoryPath = $"{_originalAssemblyFile.DirectoryName}\\Content\\"; + #endregion - return $"{contentDirectoryPath}{fileName}"; - } + #region Utilites - /// - /// Install available plugin localizations - /// - protected virtual void InstallLocalization() - { - var allLanguages = _languageService.GetAllLanguages(); - var language = allLanguages.FirstOrDefault(); + /// + /// Generate localization file path by language culture + /// + /// Language culture. For example 'en-US' + /// Localization Xml file path + protected string GenerateLocalizationXmlFilePathByCulture(string culture = "en-US") + { + string fileName = string.Format("localization.{0}.xml", culture); + string contentDirectoryPath = $"{_originalAssemblyFile.DirectoryName}\\Content\\"; - //if shop have no available languages method generate exception - if (language == null) - throw new Exception("Your store have no available language."); + return $"{contentDirectoryPath}{fileName}"; + } - foreach (var l in allLanguages) + /// + /// Install available plugin localizations + /// + protected virtual void InstallLocalization() { - //check file existing - bool isLocalizationFileExist = File.Exists(GenerateLocalizationXmlFilePathByCulture(l.LanguageCulture)); + var allLanguages = _languageService.GetAllLanguages(); + var language = allLanguages.FirstOrDefault(); - //get localization file path. If no one localization have no appropriate xml file method will install only default english localization - string localizationPath = isLocalizationFileExist ? GenerateLocalizationXmlFilePathByCulture(l.LanguageCulture) : GenerateLocalizationXmlFilePathByCulture(); + //if shop have no available languages method generate exception + if (language == null) + throw new Exception("Your store have no available language."); - //if file exists it's imports in database - var localizationFile = File.ReadAllBytes(localizationPath); - using (var stream = new MemoryStream(localizationFile)) + foreach (var l in allLanguages) { - using (var sr = new StreamReader(stream, Encoding.UTF8)) + //check file existing + bool isLocalizationFileExist = File.Exists(GenerateLocalizationXmlFilePathByCulture(l.LanguageCulture)); + + //get localization file path. If no one localization have no appropriate xml file method will install only default english localization + string localizationPath = isLocalizationFileExist ? GenerateLocalizationXmlFilePathByCulture(l.LanguageCulture) : GenerateLocalizationXmlFilePathByCulture(); + + //if file exists it's imports in database + var localizationFile = File.ReadAllBytes(localizationPath); + using (var stream = new MemoryStream(localizationFile)) { - _localizationService.ImportResourcesFromXml(l, sr); + using (var sr = new StreamReader(stream, Encoding.UTF8)) + { + _localizationService.ImportResourcesFromXml(l, sr); + } } } } - } - /// - /// Uninstall plugin localization - /// - protected virtual void UninstallLocalization() - { - var localizationPath = GenerateLocalizationXmlFilePathByCulture(); + /// + /// Uninstall plugin localization + /// + protected virtual void UninstallLocalization() + { + var localizationPath = GenerateLocalizationXmlFilePathByCulture(); - //if standart english localization file isn't exist method generate exception - if (!File.Exists(localizationPath)) - throw new Exception("File isn't exist."); + //if standart english localization file isn't exist method generate exception + if (!File.Exists(localizationPath)) + throw new Exception("File isn't exist."); - var localizationFile = File.ReadAllBytes(localizationPath); + var localizationFile = File.ReadAllBytes(localizationPath); - using (var stream = new MemoryStream(localizationFile)) - { - using (var sr = new StreamReader(stream, Encoding.UTF8)) + using (var stream = new MemoryStream(localizationFile)) { - string result = sr.ReadToEnd(); - XmlDocument xLang = new XmlDocument(); - xLang.LoadXml(result); - - //get localization keys - XmlNodeList xNodeList = xLang.SelectNodes("Language/LocaleResource"); - foreach (XmlNode elem in xNodeList) - if (elem.Name == "LocaleResource") - { - var localResource = elem.Attributes["Name"].Value; - _localizationService.DeletePluginLocaleResource(localResource); - } + using (var sr = new StreamReader(stream, Encoding.UTF8)) + { + string result = sr.ReadToEnd(); + XmlDocument xLang = new XmlDocument(); + xLang.LoadXml(result); + + //get localization keys + XmlNodeList xNodeList = xLang.SelectNodes("Language/LocaleResource"); + foreach (XmlNode elem in xNodeList) + if (elem.Name == "LocaleResource") + { + var localResource = elem.Attributes["Name"].Value; + _localizationService.DeletePluginLocaleResource(localResource); + } + } } } - } - - /// - /// Check current plugin installation status in 'InstalledPlugins.txt' document - /// - /// Plugin system name - /// True - when plugin marked like installed - protected static bool IsPluginInstalled() - { - return IsPluginInstalled(BaroquePluginDescriptor.SystemName); - } - - #endregion - #region Methods + #endregion - public override void Install() - { - this.InstallLocalization(); - base.Install(); - } - - public override void Uninstall() - { - this.UninstallLocalization(); - base.Uninstall(); - } + #region Methods - /// - /// Check InstalledPlugins.txt file list on plugin system name - /// - /// Plugin system name - /// True when plugin added to list - public static bool IsPluginInstalled(string systemName) - { - string installedPluginsFile = CommonHelper.DefaultFileProvider.MapPath(NopPluginDefaults.PluginsInfoFilePath); - - if (File.Exists(installedPluginsFile)) + public override void Install() { - var redisPluginsInfo = JsonConvert.DeserializeObject(File.ReadAllText(installedPluginsFile)); - + this.InstallLocalization(); + base.Install(); + } - return redisPluginsInfo.InstalledPluginNames.Contains(systemName); + public override void Uninstall() + { + this.UninstallLocalization(); + base.Uninstall(); } - return false; + #endregion } - - #endregion } -} + diff --git a/Service/WidgetZoneService.cs b/Service/WidgetZoneService.cs index e81cb0e..efdb4d6 100644 --- a/Service/WidgetZoneService.cs +++ b/Service/WidgetZoneService.cs @@ -70,7 +70,7 @@ public virtual WidgetZone GetWidgetZoneById(int id) /// Widget zone entity public virtual WidgetZone GetWidgetZoneBySystemName(string systemName) { - return _widgetZoneRepository.Table.FirstOrDefault(x => x.SystemName.Equals(systemName)); + return _widgetZoneRepository.Table.FirstOrDefault(x => x.SystemName.Equals(systemName) && x.Published); } /// @@ -87,7 +87,7 @@ public virtual IPagedList GetNopCommerceWidgetZones(string systemName = { var value = property.GetValue(null); return value != null ? value.ToString() : string.Empty; - }).Where(x => !string.IsNullOrEmpty(x) && x.Contains(systemName)).ToList(); + }).Where(x => !string.IsNullOrEmpty(x) && x.Contains(systemName, StringComparison.InvariantCultureIgnoreCase)).ToList(); return new PagedList(publicWidgetZones, pageIndex, pageSize); } diff --git a/Views/Admin/Configure.cshtml b/Views/Admin/Configure.cshtml index 8ce44e1..7550e5d 100644 --- a/Views/Admin/Configure.cshtml +++ b/Views/Admin/Configure.cshtml @@ -7,6 +7,14 @@
+
+
+
+ + qBoSlider extend nopCommerce menu and now you can edit slide collection from admin menu panel. Click here to edit SLIDES, and here to edit WIDGET ZONES. Visit 'Get Started' page. +
+
+
diff --git a/Views/Admin/WidgetZone/Edit.cshtml b/Views/Admin/WidgetZone/Edit.cshtml index 6f5a776..a6f4d47 100644 --- a/Views/Admin/WidgetZone/Edit.cshtml +++ b/Views/Admin/WidgetZone/Edit.cshtml @@ -10,7 +10,7 @@

- @T("Nop.Plugin.Baroque.Widgets.qBoSlider.Admin.WidgetZone.Edit") + @T("Nop.Plugin.Baroque.Widgets.qBoSlider.Admin.WidgetZone.Edit") - @Model.Name @T("Nop.Plugin.Baroque.Widgets.qBoSlider.Admin.WidgetZone.BackToList") diff --git a/plugin.json b/plugin.json index 65a6cf9..2d8023c 100644 --- a/plugin.json +++ b/plugin.json @@ -2,7 +2,7 @@ "Group": "Widgets", "FriendlyName": "qBoSlider", "SystemName": "Widgets.qBoSlider", - "Version": "1.3.0", + "Version": "1.3.1", "SupportedVersions": [ "4.30" ], "Author": "Baroque team", "DisplayOrder": 1, diff --git a/qBoSliderPlugin.cs b/qBoSliderPlugin.cs index ed0479a..610f5b9 100644 --- a/qBoSliderPlugin.cs +++ b/qBoSliderPlugin.cs @@ -199,7 +199,6 @@ public override void Install() //install simple data //get sample pictures path var sampleImagesPath = CommonHelper.DefaultFileProvider.MapPath("~/Plugins/Widgets.qBoSlider/Content/sample-images/"); - var slides = _sliderContext.Set(); var picture1 = _pictureService.InsertPicture(File.ReadAllBytes(string.Format("{0}banner1.jpg", sampleImagesPath)), "image/pjpeg", "qboslide-1").Id; var slide1 = new Slide()