Skip to content

Commit 2498800

Browse files
committed
Store scoped plugins: the query to determine active store plugins could resolve wrong plugins
1 parent 3051f06 commit 2498800

2 files changed

Lines changed: 30 additions & 7 deletions

File tree

src/Libraries/SmartStore.Core/Extensions/StringExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ public static string SplitPascalCase(this string value)
506506

507507
return sb.ToString();
508508
}
509-
/// <remarks>codehint: sm-add</remarks>
509+
510510
[DebuggerStepThrough]
511511
public static string[] SplitSafe(this string value, string separator)
512512
{
@@ -979,10 +979,10 @@ private static string ToValidPathInternal(this string input, bool isPath, string
979979
[DebuggerStepThrough]
980980
public static int[] ToIntArray(this string s)
981981
{
982-
return Array.ConvertAll(s.SplitSafe(","), v => int.Parse(v));
982+
return Array.ConvertAll(s.SplitSafe(","), v => int.Parse(v.Trim()));
983983
}
984984

985-
//[DebuggerStepThrough]
985+
[DebuggerStepThrough]
986986
public static bool ToIntArrayContains(this string s, int value, bool defaultValue)
987987
{
988988
if (s == null)

src/Presentation/SmartStore.Web.Framework/Plugins/ProviderManager.cs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public Provider<TProvider> GetProvider<TProvider>(string systemName, int storeId
3232
if (storeId > 0)
3333
{
3434
var d = provider.Metadata.PluginDescriptor;
35-
if (d != null && _services.Settings.GetSettingByKey<string>(d.GetSettingKey("LimitedToStores")).ToIntArrayContains(storeId, false))
35+
if (d != null && !IsActiveForStore(d, storeId))
3636
{
3737
return null;
3838
}
@@ -53,7 +53,7 @@ public Provider<IProvider> GetProvider(string systemName, int storeId = 0)
5353
if (storeId > 0)
5454
{
5555
var d = provider.Metadata.PluginDescriptor;
56-
if (d != null && _services.Settings.GetSettingByKey<string>(d.GetSettingKey("LimitedToStores")).ToIntArrayContains(storeId, false))
56+
if (d != null && !IsActiveForStore(d, storeId))
5757
{
5858
return null;
5959
}
@@ -71,7 +71,7 @@ public IEnumerable<Provider<TProvider>> GetAllProviders<TProvider>(int storeId =
7171
{
7272
providers = from p in providers
7373
let d = p.Metadata.PluginDescriptor
74-
where d == null || !_services.Settings.GetSettingByKey<string>(d.GetSettingKey("LimitedToStores")).ToIntArrayContains(storeId, false)
74+
where d == null || IsActiveForStore(d, storeId)
7575
select p;
7676
}
7777
return SortProviders(providers.Select(x => new Provider<TProvider>(x)));
@@ -84,7 +84,7 @@ public IEnumerable<Provider<IProvider>> GetAllProviders(int storeId = 0)
8484
{
8585
providers = from p in providers
8686
let d = p.Metadata.PluginDescriptor
87-
where d == null || !_services.Settings.GetSettingByKey<string>(d.GetSettingKey("LimitedToStores")).ToIntArrayContains(storeId, false)
87+
where d == null || IsActiveForStore(d, storeId)
8888
select p;
8989
}
9090
return SortProviders(providers.Select(x => new Provider<IProvider>(x)));
@@ -125,6 +125,29 @@ protected virtual void SetUserData(ProviderMetadata metadata)
125125
}
126126
}
127127

128+
private bool IsActiveForStore(PluginDescriptor plugin, int storeId)
129+
{
130+
if (storeId == 0)
131+
{
132+
return true;
133+
}
134+
135+
var limitedToStoresSetting = _services.Settings.GetSettingByKey<string>(plugin.GetSettingKey("LimitedToStores"));
136+
if (limitedToStoresSetting.IsEmpty())
137+
{
138+
return true;
139+
}
140+
141+
var limitedToStores = limitedToStoresSetting.ToIntArray();
142+
if (limitedToStores.Length > 0)
143+
{
144+
var flag = limitedToStores.Contains(storeId);
145+
return flag;
146+
}
147+
148+
return true;
149+
}
150+
128151
}
129152

130153
}

0 commit comments

Comments
 (0)