Skip to content

Commit ccd35b6

Browse files
committed
Added support for Specifying Caching level
1 parent adec159 commit ccd35b6

File tree

4 files changed

+86
-3
lines changed

4 files changed

+86
-3
lines changed

src/Umbraco.Cms.Integrations.Commerce.Shopify/Configuration/ShopifySettings.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
using System.Collections.Specialized;
2+
#if NETCOREAPP
3+
using Umbraco.Cms.Core.PropertyEditors;
4+
#else
5+
using Umbraco.Core.PropertyEditors;
6+
#endif
27

38
namespace Umbraco.Cms.Integrations.Commerce.Shopify.Configuration
49
{
510
public class ShopifySettings
611
{
712
public ShopifySettings()
813
{
9-
14+
1015
}
1116

1217
public ShopifySettings(NameValueCollection appSettings)
@@ -17,6 +22,26 @@ public ShopifySettings(NameValueCollection appSettings)
1722
UseUmbracoAuthorization = bool.TryParse(appSettings[Constants.Configuration.UmbracoCmsIntegrationsCommerceShopifyUseUmbracoAuthorizationKey], out var key)
1823
? key
1924
: true;
25+
26+
// Enum.TryParse introduced in .NET site is .NETFramework and .NET Core, same logic will work for both
27+
switch (appSettings[Constants.Configuration.UmbracoCmsIntegrationsCommerceShopifyPropertyCacheLevel])
28+
{
29+
case "Unknown":
30+
CacheLevel = PropertyCacheLevel.Unknown;
31+
break;
32+
case "Element":
33+
CacheLevel = PropertyCacheLevel.Element;
34+
break;
35+
case "Elements":
36+
CacheLevel = PropertyCacheLevel.Elements;
37+
break;
38+
case "None":
39+
CacheLevel = PropertyCacheLevel.None;
40+
break;
41+
default:
42+
CacheLevel = PropertyCacheLevel.Snapshot;
43+
break;
44+
}
2045
}
2146

2247
public string ApiVersion { get; set; }
@@ -26,5 +51,7 @@ public ShopifySettings(NameValueCollection appSettings)
2651
public string AccessToken { get; set; }
2752

2853
public bool UseUmbracoAuthorization { get; set; } = true;
54+
55+
public PropertyCacheLevel CacheLevel { get; set; } = PropertyCacheLevel.Snapshot;
2956
}
3057
}

src/Umbraco.Cms.Integrations.Commerce.Shopify/Constants.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public static class Configuration
4747
public const string UmbracoCmsIntegrationsCommerceShopifyScopesKey = "Umbraco.Cms.Integrations.Commerce.Shopify.Scopes";
4848

4949
public const string UmbracoCmsIntegrationsCommerceShopifyTokenEndpointKey = "Umbraco.Cms.Integrations.Commerce.Shopify.TokenEndpoint";
50+
51+
public const string UmbracoCmsIntegrationsCommerceShopifyPropertyCacheLevel =
52+
"Umbraco.Cms.Integrations.Commerce.Shopify.PropertyCacheLevel";
5053
}
5154

5255
public static class PropertyEditors

src/Umbraco.Cms.Integrations.Commerce.Shopify/Editors/ShopifyProductPickerValueConverter.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,36 @@
44
using System.Threading.Tasks;
55
using Umbraco.Cms.Integrations.Commerce.Shopify.Models.ViewModels;
66
using Umbraco.Cms.Integrations.Commerce.Shopify.Services;
7+
using Umbraco.Cms.Integrations.Commerce.Shopify.Configuration;
78

89
#if NETCOREAPP
10+
using Microsoft.Extensions.Options;
911
using Umbraco.Cms.Core.PropertyEditors;
1012
using Umbraco.Cms.Core.Models.PublishedContent;
1113
#else
1214
using Umbraco.Core.Models.PublishedContent;
1315
using Umbraco.Core.PropertyEditors;
16+
using System.Configuration;
1417
#endif
1518

1619
namespace Umbraco.Cms.Integrations.Commerce.Shopify.Editors
1720
{
1821
public class ShopifyProductPickerValueConverter : PropertyValueConverterBase
1922
{
2023
private readonly IShopifyService _apiService;
24+
private readonly ShopifySettings _settings;
2125

26+
#if NETCOREAPP
27+
public ShopifyProductPickerValueConverter(IOptions<ShopifySettings> options, IShopifyService apiService)
28+
#else
2229
public ShopifyProductPickerValueConverter(IShopifyService apiService)
30+
#endif
2331
{
32+
#if NETCOREAPP
33+
_settings = options.Value;
34+
#else
35+
_settings = new ShopifySettings(ConfigurationManager.AppSettings);
36+
#endif
2437
_apiService = apiService;
2538
}
2639

@@ -30,7 +43,7 @@ public override bool IsConverter(IPublishedPropertyType propertyType) =>
3043
public override Type GetPropertyValueType(IPublishedPropertyType propertyType) => typeof(List<ProductViewModel>);
3144

3245
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType) =>
33-
PropertyCacheLevel.Snapshot;
46+
_settings.CacheLevel;
3447

3548
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source,
3649
bool preview)

src/Umbraco.Cms.Integrations.Commerce.Shopify/Umbraco.Cms.Integrations.Commerce.Shopify.csproj

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>net472;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
3+
<TargetFrameworks>net8.0</TargetFrameworks>
44
</PropertyGroup>
55

66
<PropertyGroup>
@@ -18,6 +18,46 @@
1818
<PackageReadmeFile>readme.md</PackageReadmeFile>
1919
</PropertyGroup>
2020

21+
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net472|AnyCPU'">
22+
<DefineConstants>$(DefineConstants);NETCOREAPP</DefineConstants>
23+
</PropertyGroup>
24+
25+
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net5.0|AnyCPU'">
26+
<DefineConstants>$(DefineConstants);NETCOREAPP</DefineConstants>
27+
</PropertyGroup>
28+
29+
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net6.0|AnyCPU'">
30+
<DefineConstants>$(DefineConstants);NETCOREAPP</DefineConstants>
31+
</PropertyGroup>
32+
33+
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net7.0|AnyCPU'">
34+
<DefineConstants>$(DefineConstants);NETCOREAPP</DefineConstants>
35+
</PropertyGroup>
36+
37+
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0|AnyCPU'">
38+
<DefineConstants>$(DefineConstants);NETCOREAPP</DefineConstants>
39+
</PropertyGroup>
40+
41+
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net472|AnyCPU'">
42+
<DefineConstants>$(DefineConstants);NETCOREAPP</DefineConstants>
43+
</PropertyGroup>
44+
45+
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net5.0|AnyCPU'">
46+
<DefineConstants>$(DefineConstants);NETCOREAPP</DefineConstants>
47+
</PropertyGroup>
48+
49+
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net6.0|AnyCPU'">
50+
<DefineConstants>$(DefineConstants);NETCOREAPP</DefineConstants>
51+
</PropertyGroup>
52+
53+
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net7.0|AnyCPU'">
54+
<DefineConstants>$(DefineConstants);NETCOREAPP</DefineConstants>
55+
</PropertyGroup>
56+
57+
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0|AnyCPU'">
58+
<DefineConstants>$(DefineConstants);NETCOREAPP</DefineConstants>
59+
</PropertyGroup>
60+
2161
<ItemGroup Condition="'$(TargetFramework)' == 'net472'">
2262
<PackageReference Include="UmbracoCms.Web" version="8.5.4" />
2363
</ItemGroup>

0 commit comments

Comments
 (0)