Skip to content

Commit ccd2e96

Browse files
authored
Merge pull request #240 from RachBreeze/ShopifyCacheLevel
Shopify cache level
2 parents adec159 + 976437a commit ccd2e96

File tree

4 files changed

+47
-4
lines changed

4 files changed

+47
-4
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+
PropertyCacheLevel = PropertyCacheLevel.Unknown;
31+
break;
32+
case "Element":
33+
PropertyCacheLevel = PropertyCacheLevel.Element;
34+
break;
35+
case "Elements":
36+
PropertyCacheLevel = PropertyCacheLevel.Elements;
37+
break;
38+
case "None":
39+
PropertyCacheLevel = PropertyCacheLevel.None;
40+
break;
41+
default:
42+
PropertyCacheLevel = 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 PropertyCacheLevel { 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.PropertyCacheLevel;
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@
3636
<PackageReference Include="Umbraco.Cms.Web.Website" version="[11.0.0,13)" />
3737
<PackageReference Include="Umbraco.Cms.Web.BackOffice" version="[11.0.0,13)" />
3838
</ItemGroup>
39-
39+
4040
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
4141
<PackageReference Include="Umbraco.Cms.Web.Website" version="[13.0.0,14)" />
4242
<PackageReference Include="Umbraco.Cms.Web.BackOffice" version="[13.0.0,14)" />
4343
</ItemGroup>
44-
44+
4545
<ItemGroup>
4646
<Content Include="App_Plugins\UmbracoCms.Integrations\Commerce\Shopify\**\*.*">
4747
<Pack>true</Pack>

0 commit comments

Comments
 (0)