protected virtual PluginModel PreparePluginModel(PluginDescriptor pluginDescriptor, bool prepareLocales = true, bool prepareStores = true) { var pluginModel = pluginDescriptor.ToModel(); //logo pluginModel.LogoUrl = pluginDescriptor.GetLogoUrl(_webHelper); if (prepareLocales) { //locales AddLocales(_languageService, pluginModel.Locales, (locale, languageId) => { locale.FriendlyName = pluginDescriptor.Instance().GetLocalizedFriendlyName(_localizationService, languageId, false); }); } if (prepareStores) { //stores pluginModel.AvailableStores = _storeService .GetAllStores() .Select(s => s.ToModel()) .ToList(); pluginModel.SelectedStoreIds = pluginDescriptor.LimitedToStores.ToArray(); pluginModel.LimitedToStores = pluginDescriptor.LimitedToStores.Count > 0; } //configuration URL return pluginModel; }
/// <summary> /// Prepare plugin model /// </summary> /// <param name="model">Plugin model</param> /// <param name="pluginDescriptor">Plugin descriptor</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns>Plugin model</returns> public virtual PluginModel PreparePluginModel(PluginModel model, PluginDescriptor pluginDescriptor, bool excludeProperties = false) { Action <PluginLocalizedModel, int> localizedModelConfiguration = null; if (pluginDescriptor != null) { //fill in model values from the entity model = model ?? pluginDescriptor.ToModel(); model.LogoUrl = pluginDescriptor.GetLogoUrl(_webHelper); model.SelectedStoreIds = pluginDescriptor.LimitedToStores; model.SelectedCustomerRoleIds = pluginDescriptor.LimitedToCustomerRoles; if (pluginDescriptor.Installed) { PrepareInstalledPluginModel(model, pluginDescriptor.Instance()); } //define localized model configuration action localizedModelConfiguration = (locale, languageId) => { var plugin = pluginDescriptor.Instance(); locale.FriendlyName = plugin.GetLocalizedFriendlyName(_localizationService, languageId, false); }; } //prepare localized models if (!excludeProperties) { model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration); } //prepare model customer roles _aclSupportedModelFactory.PrepareModelCustomerRoles(model); //prepare available stores _storeMappingSupportedModelFactory.PrepareModelStores(model); return(model); }
protected virtual PluginModel PreparePluginModel(PluginDescriptor pluginDescriptor, bool prepareLocales = true, bool prepareStores = true) { var pluginModel = pluginDescriptor.ToModel(); //logo pluginModel.LogoUrl = pluginDescriptor.GetLogoUrl(_webHelper); if (prepareLocales) { //locales AddLocales(_languageService, pluginModel.Locales, (locale, languageId) => { locale.FriendlyName = pluginDescriptor.Instance().GetLocalizedFriendlyName(_localizationService, languageId, false); }); } if (prepareStores) { //stores pluginModel.AvailableStores = _storeService .GetAllStores() .Select(s => s.ToModel()) .ToList(); pluginModel.SelectedStoreIds = pluginDescriptor.LimitedToStores.ToArray(); pluginModel.LimitedToStores = pluginDescriptor.LimitedToStores.Count > 0; } //configuration URLs if (pluginDescriptor.Installed) { //specify configuration URL only when a plugin is already installed //plugins do not provide a general URL for configuration //because some of them have some custom URLs for configuration //for example, discount requirement plugins require additional parameters and attached to a certain discount var pluginInstance = pluginDescriptor.Instance(); string configurationUrl = null; if (pluginInstance is IPaymentMethod) { //payment plugin configurationUrl = Url.Action("ConfigureMethod", "Payment", new { systemName = pluginDescriptor.SystemName }); } else if (pluginInstance is IShippingRateComputationMethod) { //shipping rate computation method configurationUrl = Url.Action("ConfigureProvider", "Shipping", new { systemName = pluginDescriptor.SystemName }); } else if (pluginInstance is ITaxProvider) { //tax provider configurationUrl = Url.Action("ConfigureProvider", "Tax", new { systemName = pluginDescriptor.SystemName }); } else if (pluginInstance is IExternalAuthenticationMethod) { //external auth method configurationUrl = Url.Action("ConfigureMethod", "ExternalAuthentication", new { systemName = pluginDescriptor.SystemName }); } else if (pluginInstance is IWidgetPlugin) { //Misc plugins configurationUrl = Url.Action("ConfigureWidget", "Widget", new { systemName = pluginDescriptor.SystemName }); } else if (pluginInstance is IMiscPlugin) { //Misc plugins configurationUrl = Url.Action("ConfigureMiscPlugin", "Plugin", new { systemName = pluginDescriptor.SystemName }); } pluginModel.ConfigurationUrl = configurationUrl; //enabled/disabled (only for some plugin types) if (pluginInstance is IPaymentMethod) { //payment plugin pluginModel.CanChangeEnabled = true; pluginModel.IsEnabled = ((IPaymentMethod)pluginInstance).IsPaymentMethodActive(_paymentSettings); } else if (pluginInstance is IShippingRateComputationMethod) { //shipping rate computation method pluginModel.CanChangeEnabled = true; pluginModel.IsEnabled = ((IShippingRateComputationMethod)pluginInstance).IsShippingRateComputationMethodActive(_shippingSettings); } else if (pluginInstance is ITaxProvider) { //tax provider pluginModel.CanChangeEnabled = true; pluginModel.IsEnabled = pluginDescriptor.SystemName.Equals(_taxSettings.ActiveTaxProviderSystemName, StringComparison.OrdinalIgnoreCase); } else if (pluginInstance is IExternalAuthenticationMethod) { //external auth method pluginModel.CanChangeEnabled = true; pluginModel.IsEnabled = ((IExternalAuthenticationMethod)pluginInstance).IsMethodActive(_externalAuthenticationSettings); } else if (pluginInstance is IWidgetPlugin) { //Misc plugins pluginModel.CanChangeEnabled = true; pluginModel.IsEnabled = ((IWidgetPlugin)pluginInstance).IsWidgetActive(_widgetSettings); } } return(pluginModel); }
protected virtual PluginModel PreparePluginModel(PluginDescriptor pluginDescriptor, bool prepareLocales = true, bool prepareStores = true) { var pluginModel = pluginDescriptor.ToModel(); //logo pluginModel.LogoUrl = pluginDescriptor.GetLogoUrl(_webHelper); if (prepareLocales) { //locales AddLocales(_languageService, pluginModel.Locales, (locale, languageId) => { locale.FriendlyName = pluginDescriptor.Instance().GetLocalizedFriendlyName(_localizationService, languageId, false); }); } if (prepareStores) { //stores pluginModel.SelectedStoreIds = pluginDescriptor.LimitedToStores.ToList(); var allStores = _storeService.GetAllStores(); foreach (var store in allStores) { pluginModel.AvailableStores.Add(new SelectListItem { Text = store.Name, Value = store.Id.ToString(), Selected = pluginModel.SelectedStoreIds.Contains(store.Id) }); } } //configuration URLs if (pluginDescriptor.Installed) { //specify configuration URL only when a plugin is already installed //plugins do not provide a general URL for configuration //because some of them have some custom URLs for configuration //for example, discount requirement plugins require additional parameters and attached to a certain discount var pluginInstance = pluginDescriptor.Instance(); string configurationUrl = null; if (pluginInstance is IPaymentMethod) { //payment plugin configurationUrl = Url.Action("ConfigureMethod", "Payment", new { systemName = pluginDescriptor.SystemName }); } else if (pluginInstance is IShippingRateComputationMethod) { //shipping rate computation method configurationUrl = Url.Action("ConfigureProvider", "Shipping", new { systemName = pluginDescriptor.SystemName }); } else if (pluginInstance is IPickupPointProvider) { //pickup point provider configurationUrl = Url.Action("ConfigurePickupPointProvider", "Shipping", new { systemName = pluginDescriptor.SystemName }); } else if (pluginInstance is ITaxProvider) { //tax provider configurationUrl = Url.Action("ConfigureProvider", "Tax", new { systemName = pluginDescriptor.SystemName }); } else if (pluginInstance is IExternalAuthenticationMethod) { //external auth method configurationUrl = Url.Action("ConfigureMethod", "ExternalAuthentication", new { systemName = pluginDescriptor.SystemName }); } else if (pluginInstance is IWidgetPlugin) { //Misc plugins configurationUrl = Url.Action("ConfigureWidget", "Widget", new { systemName = pluginDescriptor.SystemName }); } else if (pluginInstance is IMiscPlugin) { //Misc plugins configurationUrl = Url.Action("ConfigureMiscPlugin", "Plugin", new { systemName = pluginDescriptor.SystemName }); } pluginModel.ConfigurationUrl = configurationUrl; //enabled/disabled (only for some plugin types) if (pluginInstance is IPaymentMethod) { //payment plugin pluginModel.CanChangeEnabled = true; pluginModel.IsEnabled = ((IPaymentMethod)pluginInstance).IsPaymentMethodActive(_paymentSettings); } else if (pluginInstance is IShippingRateComputationMethod) { //shipping rate computation method pluginModel.CanChangeEnabled = true; pluginModel.IsEnabled = ((IShippingRateComputationMethod)pluginInstance).IsShippingRateComputationMethodActive(_shippingSettings); } else if (pluginInstance is IPickupPointProvider) { //pickup point provider pluginModel.CanChangeEnabled = true; pluginModel.IsEnabled = ((IPickupPointProvider)pluginInstance).IsPickupPointProviderActive(_shippingSettings); } else if (pluginInstance is ITaxProvider) { //tax provider pluginModel.CanChangeEnabled = true; pluginModel.IsEnabled = pluginDescriptor.SystemName.Equals(_taxSettings.ActiveTaxProviderSystemName, StringComparison.InvariantCultureIgnoreCase); } else if (pluginInstance is IExternalAuthenticationMethod) { //external auth method pluginModel.CanChangeEnabled = true; pluginModel.IsEnabled = ((IExternalAuthenticationMethod)pluginInstance).IsMethodActive(_externalAuthenticationSettings); } else if (pluginInstance is IWidgetPlugin) { //Misc plugins pluginModel.CanChangeEnabled = true; pluginModel.IsEnabled = ((IWidgetPlugin)pluginInstance).IsWidgetActive(_widgetSettings); } } return pluginModel; }
protected virtual PluginModel PreparePluginModel(PluginDescriptor pluginDescriptor, bool prepareLocales = true) { var pluginModel = pluginDescriptor.ToModel(); //logo pluginModel.LogoUrl = pluginDescriptor.GetLogoUrl(_webHelper); if (prepareLocales) { //locales AddLocales(_languageService, pluginModel.Locales, (locale, languageId) => { locale.FriendlyName = pluginDescriptor.Instance() .GetLocalizedFriendlyName(_localizationService, languageId, false); }); } //configuration URLs if (pluginDescriptor.Installed) { //specify configuration URL only when a plugin is already installed //plugins do not provide a general URL for configuration //because some of them have some custom URLs for configuration //for example, discount requirement plugins require additional parameters and attached to a certain discount var pluginInstance = pluginDescriptor.Instance(); string configurationUrl = null; if (pluginInstance is IExternalAuthenticationMethod) { //external auth method configurationUrl = Url.Action("ConfigureMethod", "ExternalAuthentication", new { systemName = pluginDescriptor.SystemName }); } else if (pluginInstance is IWidgetPlugin) { //Misc plugins configurationUrl = Url.Action("ConfigureWidget", "Widget", new { systemName = pluginDescriptor.SystemName }); } else if (pluginInstance is IMiscPlugin) { //Misc plugins configurationUrl = Url.Action("ConfigureMiscPlugin", "Plugin", new { systemName = pluginDescriptor.SystemName }); } pluginModel.ConfigurationUrl = configurationUrl; //enabled/disabled (only for some plugin types) if (pluginInstance is IExternalAuthenticationMethod) { //external auth method pluginModel.CanChangeEnabled = true; pluginModel.IsEnabled = ((IExternalAuthenticationMethod)pluginInstance).IsMethodActive(_externalAuthenticationSettings); } else if (pluginInstance is IWidgetPlugin) { //Misc plugins pluginModel.CanChangeEnabled = true; pluginModel.IsEnabled = ((IWidgetPlugin)pluginInstance).IsWidgetActive(_widgetSettings); } } return(pluginModel); }
protected virtual PluginModel PreparePluginModel(PluginDescriptor pluginDescriptor, bool prepareLocales = true, bool prepareStores = true, bool prepareAcl = true) { var pluginModel = pluginDescriptor.ToModel(); //logo pluginModel.LogoUrl = pluginDescriptor.GetLogoUrl(_webHelper); if (prepareLocales) { //locales AddLocales(_languageService, pluginModel.Locales, (locale, languageId) => { locale.FriendlyName = pluginDescriptor.Instance().GetLocalizedFriendlyName(_localizationService, languageId, false); }); } if (prepareStores) { //stores pluginModel.SelectedStoreIds = pluginDescriptor.LimitedToStores; var allStores = _storeService.GetAllStores(); foreach (var store in allStores) { pluginModel.AvailableStores.Add(new SelectListItem { Text = store.Name, Value = store.Id.ToString(), Selected = pluginModel.SelectedStoreIds.Contains(store.Id) }); } } if (prepareAcl) { //acl pluginModel.SelectedCustomerRoleIds = pluginDescriptor.LimitedToCustomerRoles; foreach (var role in _customerService.GetAllCustomerRoles(true)) { pluginModel.AvailableCustomerRoles.Add(new SelectListItem { Text = role.Name, Value = role.Id.ToString(), Selected = pluginModel.SelectedCustomerRoleIds.Contains(role.Id) }); } } //configuration URLs if (pluginDescriptor.Installed) { //display configuration URL only when a plugin is already installed var pluginInstance = pluginDescriptor.Instance(); pluginModel.ConfigurationUrl = pluginInstance.GetConfigurationPageUrl(); //enabled/disabled (only for some plugin types) if (pluginInstance is IPaymentMethod) { //payment plugin pluginModel.CanChangeEnabled = true; pluginModel.IsEnabled = ((IPaymentMethod)pluginInstance).IsPaymentMethodActive(_paymentSettings); } else if (pluginInstance is IShippingRateComputationMethod) { //shipping rate computation method pluginModel.CanChangeEnabled = true; pluginModel.IsEnabled = ((IShippingRateComputationMethod)pluginInstance).IsShippingRateComputationMethodActive(_shippingSettings); } else if (pluginInstance is IPickupPointProvider) { //pickup point provider pluginModel.CanChangeEnabled = true; pluginModel.IsEnabled = ((IPickupPointProvider)pluginInstance).IsPickupPointProviderActive(_shippingSettings); } else if (pluginInstance is ITaxProvider) { //tax provider pluginModel.CanChangeEnabled = true; pluginModel.IsEnabled = pluginDescriptor.SystemName.Equals(_taxSettings.ActiveTaxProviderSystemName, StringComparison.InvariantCultureIgnoreCase); } else if (pluginInstance is IExternalAuthenticationMethod) { //external auth method pluginModel.CanChangeEnabled = true; pluginModel.IsEnabled = ((IExternalAuthenticationMethod)pluginInstance).IsMethodActive(_externalAuthenticationSettings); } else if (pluginInstance is IWidgetPlugin) { //Misc plugins pluginModel.CanChangeEnabled = true; pluginModel.IsEnabled = ((IWidgetPlugin)pluginInstance).IsWidgetActive(_widgetSettings); } } return(pluginModel); }
protected virtual PluginModel PreparePluginModel(PluginDescriptor pluginDescriptor, bool prepareLocales = true, bool prepareStores = true) { var pluginModel = pluginDescriptor.ToModel(); //logo pluginModel.LogoUrl = pluginDescriptor.GetLogoUrl(_webHelper); if (prepareLocales) { //locales AddLocales(_languageService, pluginModel.Locales, (locale, languageId) => { locale.FriendlyName = pluginDescriptor.Instance().GetLocalizedFriendlyName(_localizationService, languageId, false); }); } if (prepareStores) { //stores pluginModel.AvailableStores = _storeService .GetAllStores() .Select(s => s.ToModel()) .ToList(); pluginModel.SelectedStoreIds = pluginDescriptor.LimitedToStores.ToArray(); pluginModel.LimitedToStores = pluginDescriptor.LimitedToStores.Count > 0; } //configuration URLs if (pluginDescriptor.Installed) { //display configuration URL only when a plugin is already installed var pluginInstance = pluginDescriptor.Instance(); pluginModel.ConfigurationUrl = pluginInstance.GetConfigurationPageUrl(); //enabled/disabled (only for some plugin types) if (pluginInstance is IPaymentMethod) { //payment plugin pluginModel.CanChangeEnabled = true; pluginModel.IsEnabled = ((IPaymentMethod)pluginInstance).IsPaymentMethodActive(_paymentSettings); } else if (pluginInstance is IShippingRateComputationMethod) { //shipping rate computation method pluginModel.CanChangeEnabled = true; pluginModel.IsEnabled = ((IShippingRateComputationMethod)pluginInstance).IsShippingRateComputationMethodActive(_shippingSettings); } else if (pluginInstance is ITaxProvider) { //tax provider pluginModel.CanChangeEnabled = true; pluginModel.IsEnabled = pluginDescriptor.SystemName.Equals(_taxSettings.ActiveTaxProviderSystemName, StringComparison.OrdinalIgnoreCase); } else if (pluginInstance is IExternalAuthenticationMethod) { //external auth method pluginModel.CanChangeEnabled = true; pluginModel.IsEnabled = ((IExternalAuthenticationMethod)pluginInstance).IsMethodActive(_externalAuthenticationSettings); } else if (pluginInstance is IWidgetPlugin) { //Misc plugins pluginModel.CanChangeEnabled = true; pluginModel.IsEnabled = ((IWidgetPlugin)pluginInstance).IsWidgetActive(_widgetSettings); } } return(pluginModel); }
protected virtual PluginModel PreparePluginModel(PluginDescriptor pluginDescriptor, bool prepareLocales = true, bool prepareStores = true, bool prepareAcl = true) { var pluginModel = pluginDescriptor.ToModel(); //logo pluginModel.LogoUrl = pluginDescriptor.GetLogoUrl(_webHelper); if (prepareLocales) { //locales AddLocales(_languageService, pluginModel.Locales, (locale, languageId) => { locale.FriendlyName = pluginDescriptor.Instance().GetLocalizedFriendlyName(_localizationService, languageId, false); }); } if (prepareStores) { //stores pluginModel.SelectedStoreIds = pluginDescriptor.LimitedToStores; var allStores = _storeService.GetAllStores(); foreach (var store in allStores) { pluginModel.AvailableStores.Add(new SelectListItem { Text = store.Name, Value = store.Id.ToString(), Selected = pluginModel.SelectedStoreIds.Contains(store.Id) }); } } if (prepareAcl) { //acl pluginModel.SelectedCustomerRoleIds = pluginDescriptor.LimitedToCustomerRoles; foreach (var role in _customerService.GetAllCustomerRoles(true)) { pluginModel.AvailableCustomerRoles.Add(new SelectListItem { Text = role.Name, Value = role.Id.ToString(), Selected = pluginModel.SelectedCustomerRoleIds.Contains(role.Id) }); } } //configuration URLs if (pluginDescriptor.Installed) { //specify configuration URL only when a plugin is already installed //plugins do not provide a general URL for configuration //because some of them have some custom URLs for configuration //for example, discount requirement plugins require additional parameters and attached to a certain discount var pluginInstance = pluginDescriptor.Instance(); string configurationUrl = null; if (pluginInstance is IExternalAuthenticationMethod) { //external auth method configurationUrl = Url.Action("ConfigureMethod", "ExternalAuthentication", new { systemName = pluginDescriptor.SystemName }); } else if (pluginInstance is IWidgetPlugin) { //Misc plugins configurationUrl = Url.Action("ConfigureWidget", "Widget", new { systemName = pluginDescriptor.SystemName }); } else if (pluginInstance is IMiscPlugin) { //Misc plugins configurationUrl = Url.Action("ConfigureMiscPlugin", "Plugin", new { systemName = pluginDescriptor.SystemName }); } pluginModel.ConfigurationUrl = configurationUrl; //enabled/disabled (only for some plugin types) if (pluginInstance is IExternalAuthenticationMethod) { //external auth method pluginModel.CanChangeEnabled = true; pluginModel.IsEnabled = ((IExternalAuthenticationMethod)pluginInstance).IsMethodActive(_externalAuthenticationSettings); } else if (pluginInstance is IWidgetPlugin) { //Misc plugins pluginModel.CanChangeEnabled = true; pluginModel.IsEnabled = ((IWidgetPlugin)pluginInstance).IsWidgetActive(_widgetSettings); } } return(pluginModel); }