diff --git a/src/Umbraco.Commerce.DemoStore/DemoStoreBuilderExtensions.cs b/src/Umbraco.Commerce.DemoStore/DemoStoreBuilderExtensions.cs index 882e648..ff070ad 100644 --- a/src/Umbraco.Commerce.DemoStore/DemoStoreBuilderExtensions.cs +++ b/src/Umbraco.Commerce.DemoStore/DemoStoreBuilderExtensions.cs @@ -6,6 +6,8 @@ using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Extensions; using Umbraco.Cms.Core.Notifications; +using Umbraco.Commerce.DemoStore.Web.Index; +using Microsoft.Extensions.DependencyInjection; namespace Umbraco.Commerce.DemoStore { @@ -43,6 +45,7 @@ public static IUmbracoBuilder AddDemoStore(this IUmbracoBuilder umbracoBuilder) }); umbracoBuilder.AddNotificationHandler(); + umbracoBuilder.Services.ConfigureOptions(); return umbracoBuilder; } diff --git a/src/Umbraco.Commerce.DemoStore/Events/TransformExamineValues.cs b/src/Umbraco.Commerce.DemoStore/Events/TransformExamineValues.cs index 5f8b874..f6a5e73 100644 --- a/src/Umbraco.Commerce.DemoStore/Events/TransformExamineValues.cs +++ b/src/Umbraco.Commerce.DemoStore/Events/TransformExamineValues.cs @@ -8,6 +8,9 @@ using Umbraco.Extensions; using Umbraco.Commerce.DemoStore.Models; using System.Text; +using Newtonsoft.Json; +using Umbraco.Commerce.Core.Services; +using System; namespace Umbraco.Commerce.DemoStore.Events { @@ -15,19 +18,21 @@ public class TransformExamineValues : INotificationHandler { @@ -72,6 +77,20 @@ public void Handle(UmbracoApplicationStartingNotification notification) values.Add("categoryAliases", new[] { string.Join(" ", categoryAliases) }); } } + + if (e.ValueSet.Values.ContainsKey("price")) + { + var prices = JsonConvert.DeserializeObject>(e.ValueSet.GetValue("price").ToString()); + + foreach (var price in prices) + { + var currency = _currencyService.GetCurrency(price.Key); + if (currency == null) + continue; + + values.Add($"price_{currency.Code}", new[] { price.Value }); + } + } } // ================================================================ diff --git a/src/Umbraco.Commerce.DemoStore/Web/Index/ConfigureIndexOptions.cs b/src/Umbraco.Commerce.DemoStore/Web/Index/ConfigureIndexOptions.cs new file mode 100644 index 0000000..32d119d --- /dev/null +++ b/src/Umbraco.Commerce.DemoStore/Web/Index/ConfigureIndexOptions.cs @@ -0,0 +1,35 @@ +using Examine.Lucene; +using Examine; +using Microsoft.Extensions.Options; +using Lucene.Net.Facet; +using System.Collections.Generic; +using Umbraco.Cms.Core; + +namespace Umbraco.Commerce.DemoStore.Web.Index +{ + public sealed class ConfigureIndexOptions : IConfigureNamedOptions + { + public void Configure(string name, LuceneDirectoryIndexOptions options) + { + switch (name) + { + case Constants.UmbracoIndexes.ExternalIndexName: + + var priceFields = new List + { + "price_GBP" + }; + + foreach (var field in priceFields) + { + options.FieldDefinitions.TryAdd(new FieldDefinition(field, FieldDefinitionTypes.Double)); + } + + break; + } + } + + public void Configure(LuceneDirectoryIndexOptions options) + => Configure(string.Empty, options); + } +}