diff --git a/Directory.Build.props b/Directory.Build.props index d7980b9fe..f1134b83d 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -2,7 +2,7 @@ - 3.806.0 + 3.807.0 $(VersionSuffix)-$(BuildNumber) diff --git a/src/VirtoCommerce.CoreModule.Core/Seo/CompositeSeoResolver.cs b/src/VirtoCommerce.CoreModule.Core/Seo/CompositeSeoResolver.cs new file mode 100644 index 000000000..a0562fc6e --- /dev/null +++ b/src/VirtoCommerce.CoreModule.Core/Seo/CompositeSeoResolver.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace VirtoCommerce.CoreModule.Core.Seo; + +public class CompositeSeoResolver : ISeoResolver +{ + private readonly IEnumerable _resolvers; + private readonly CompositeSeoBySlugResolver _seoBySlugResolver; + + public CompositeSeoResolver(IEnumerable resolvers, CompositeSeoBySlugResolver seoBySlugResolver) + { + _resolvers = resolvers; + _seoBySlugResolver = seoBySlugResolver; + } + + public async Task> FindSeoAsync(SeoSearchCriteria criteria) + { + var tasks = _resolvers.Select(x => x.FindSeoAsync(criteria)).ToArray(); + var result = (await Task.WhenAll(tasks)).SelectMany(x => x).Where(x => x.ObjectId != null && x.ObjectType != null).Distinct(); + var fallbackResults = await _seoBySlugResolver.FindSeoBySlugAsync(criteria.Slug); + return result.Union(fallbackResults).ToList(); + } +} + diff --git a/src/VirtoCommerce.CoreModule.Core/Seo/ISeoResolver.cs b/src/VirtoCommerce.CoreModule.Core/Seo/ISeoResolver.cs new file mode 100644 index 000000000..2f486da8a --- /dev/null +++ b/src/VirtoCommerce.CoreModule.Core/Seo/ISeoResolver.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace VirtoCommerce.CoreModule.Core.Seo; + +public interface ISeoResolver +{ + Task> FindSeoAsync(SeoSearchCriteria criteria); +} diff --git a/src/VirtoCommerce.CoreModule.Core/Seo/SeoSearchCriteria.cs b/src/VirtoCommerce.CoreModule.Core/Seo/SeoSearchCriteria.cs new file mode 100644 index 000000000..ad508ff67 --- /dev/null +++ b/src/VirtoCommerce.CoreModule.Core/Seo/SeoSearchCriteria.cs @@ -0,0 +1,11 @@ +using VirtoCommerce.Platform.Core.Common; + +namespace VirtoCommerce.CoreModule.Core.Seo +{ + public class SeoSearchCriteria : SearchCriteriaBase + { + public string Slug { get; set; } + public string StoreId { get; set; } + public string Permalink { get; set; } + } +} diff --git a/src/VirtoCommerce.CoreModule.Web/Module.cs b/src/VirtoCommerce.CoreModule.Web/Module.cs index 2eb55f760..559a3a309 100644 --- a/src/VirtoCommerce.CoreModule.Web/Module.cs +++ b/src/VirtoCommerce.CoreModule.Web/Module.cs @@ -72,6 +72,7 @@ public void Initialize(IServiceCollection serviceCollection) serviceCollection.AddTransient(); serviceCollection.AddTransient(); + serviceCollection.AddTransient(); // Money rounding serviceCollection.AddTransient(); diff --git a/src/VirtoCommerce.CoreModule.Web/module.manifest b/src/VirtoCommerce.CoreModule.Web/module.manifest index a194de69e..869c9bb9b 100644 --- a/src/VirtoCommerce.CoreModule.Web/module.manifest +++ b/src/VirtoCommerce.CoreModule.Web/module.manifest @@ -1,7 +1,7 @@ VirtoCommerce.Core - 3.806.0 + 3.807.0 3.825.0 Commerce core module