Skip to content

Commit 84f4dd5

Browse files
committed
migrate to commerce v15rc1
1 parent cdf0eff commit 84f4dd5

File tree

33 files changed

+543
-400
lines changed

33 files changed

+543
-400
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<TargetFramework>net8.0</TargetFramework>
3+
<TargetFramework>net9.0</TargetFramework>
44
<Nullable>enable</Nullable>
55
<Company>Umbraco HQ</Company>
66
<Authors>Umbraco</Authors>

Directory.Packages.props

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
<GlobalPackageReference Include="Umbraco.GitVersioning.Extensions" Version="0.2.0" />
1111
</ItemGroup>
1212
<ItemGroup>
13-
<PackageVersion Include="Umbraco.Commerce.Cms.Startup" Version="[14.0.0, 15)" />
14-
<PackageVersion Include="Umbraco.Cms.Web.Website" Version="[14.0.0, 15)" />
13+
<PackageVersion Include="Umbraco.Commerce.Cms.Startup" Version="[15.0.0-rc1, 16)" />
14+
<PackageVersion Include="Umbraco.Cms.Core" Version="[15.0.0, 16)" />
15+
<PackageVersion Include="Umbraco.Cms.Web.Website" Version="[15.0.0, 16)" />
1516
</ItemGroup>
1617
</Project>

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "8.0.100",
3+
"version": "9.0.100",
44
"rollForward": "latestFeature"
55
}
66
}

src/Umbraco.Commerce.Checkout/Client/src/backoffice/dashboards/manifest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const dashboardManifests: Array<ManifestDashboard | ManifestModal> = [
66
type: 'dashboard',
77
alias: 'Umbraco.Commerce.Checkout.InstallerDashboard',
88
weight: -100,
9-
name: 'Umbraco Commerce Checkout',
9+
name: 'Umbraco Commerce Checkout v15',
1010
meta: {
1111
},
1212
element: () => import('./installer-dashboard.element'),

src/Umbraco.Commerce.Checkout/Events/ResetPaymentAndShippingMethods.cs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
using System.Threading.Tasks;
2+
using Microsoft.Extensions.Options;
13
using Umbraco.Commerce.Checkout.Configuration;
24
using Umbraco.Commerce.Common.Events;
35
using Umbraco.Commerce.Core.Events.Notification;
4-
using Microsoft.Extensions.Options;
56

67
namespace Umbraco.Commerce.Checkout.Events
78
{
@@ -13,63 +14,63 @@ namespace Umbraco.Commerce.Checkout.Events
1314

1415
public class OrderProductAddingHandler : NotificationEventHandlerBase<OrderProductAddingNotification>
1516
{
16-
public override void Handle(OrderProductAddingNotification evt)
17+
public override async Task HandleAsync(OrderProductAddingNotification evt)
1718
{
1819
if (!evt.Order.IsFinalized)
1920
{
20-
evt.Order.ClearShippingMethod();
21-
evt.Order.ClearPaymentMethod();
21+
_ = await evt.Order.ClearShippingMethodAsync();
22+
_ = await evt.Order.ClearPaymentMethodAsync();
2223
}
2324
}
2425
}
2526

2627
public class OrderLineChangingHandler : NotificationEventHandlerBase<OrderLineChangingNotification>
2728
{
28-
public override void Handle(OrderLineChangingNotification evt)
29+
public override async Task HandleAsync(OrderLineChangingNotification evt)
2930
{
3031
if (!evt.Order.IsFinalized)
3132
{
32-
evt.Order.ClearShippingMethod();
33-
evt.Order.ClearPaymentMethod();
33+
_ = await evt.Order.ClearShippingMethodAsync();
34+
_ = await evt.Order.ClearPaymentMethodAsync();
3435
}
3536
}
3637
}
3738

3839
public class OrderLineRemovingHandler : NotificationEventHandlerBase<OrderLineRemovingNotification>
3940
{
40-
public override void Handle(OrderLineRemovingNotification evt)
41+
public override async Task HandleAsync(OrderLineRemovingNotification evt)
4142
{
4243
if (!evt.Order.IsFinalized)
4344
{
44-
evt.Order.ClearShippingMethod();
45-
evt.Order.ClearPaymentMethod();
45+
_ = await evt.Order.ClearShippingMethodAsync();
46+
_ = await evt.Order.ClearPaymentMethodAsync();
4647
}
4748
}
4849
}
4950

5051
public class OrderPaymentCountryRegionChangingHandler : NotificationEventHandlerBase<OrderPaymentCountryRegionChangingNotification>
5152
{
52-
public override void Handle(OrderPaymentCountryRegionChangingNotification evt)
53+
public override async Task HandleAsync(OrderPaymentCountryRegionChangingNotification evt)
5354
{
5455
if (!evt.Order.IsFinalized)
5556
{
56-
evt.Order.ClearPaymentMethod();
57+
_ = await evt.Order.ClearPaymentMethodAsync();
5758
}
5859
}
5960
}
6061

6162
public class OrderShippingCountryRegionChangingHandler : NotificationEventHandlerBase<OrderShippingCountryRegionChangingNotification>
6263
{
63-
public override void Handle(OrderShippingCountryRegionChangingNotification evt)
64+
public override async Task HandleAsync(OrderShippingCountryRegionChangingNotification evt)
6465
{
6566
if (!evt.Order.IsFinalized)
6667
{
67-
evt.Order.ClearShippingMethod();
68-
evt.Order.ClearPaymentMethod();
68+
_ = await evt.Order.ClearShippingMethodAsync();
69+
_ = await evt.Order.ClearPaymentMethodAsync();
6970
}
7071
}
7172
}
72-
73+
7374
public class OrderShippingMethodChangingHandler : NotificationEventHandlerBase<OrderShippingMethodChangingNotification>
7475
{
7576
private readonly UmbracoCommerceCheckoutSettings _settings;
@@ -79,11 +80,11 @@ public OrderShippingMethodChangingHandler(IOptions<UmbracoCommerceCheckoutSettin
7980
_settings = settings.Value;
8081
}
8182

82-
public override void Handle(OrderShippingMethodChangingNotification evt)
83+
public override async Task HandleAsync(OrderShippingMethodChangingNotification evt)
8384
{
8485
if (!evt.Order.IsFinalized && _settings.ResetPaymentMethodOnShippingMethodChange)
8586
{
86-
evt.Order.ClearPaymentMethod();
87+
_ = await evt.Order.ClearPaymentMethodAsync();
8788
}
8889
}
8990
}

src/Umbraco.Commerce.Checkout/Events/SyncZeroValuePaymentProviderContinueUrl.cs

Lines changed: 72 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,152 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
3-
using Umbraco.Commerce.Core.Models;
4-
using Umbraco.Commerce.Core.Api;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
using Umbraco.Cms.Core;
57
using Umbraco.Cms.Core.Cache;
68
using Umbraco.Cms.Core.Events;
79
using Umbraco.Cms.Core.Models.PublishedContent;
810
using Umbraco.Cms.Core.Notifications;
9-
using Umbraco.Cms.Core.Sync;
11+
using Umbraco.Cms.Core.PublishedCache;
1012
using Umbraco.Cms.Core.Services.Changes;
13+
using Umbraco.Cms.Core.Services.Navigation;
14+
using Umbraco.Cms.Core.Sync;
1115
using Umbraco.Cms.Core.Web;
12-
using Umbraco.Extensions;
1316
using Umbraco.Commerce.Checkout.Web;
17+
using Umbraco.Commerce.Core.Api;
18+
using Umbraco.Commerce.Core.Models;
19+
using Umbraco.Commerce.Extensions;
20+
using Umbraco.Extensions;
1421

1522
namespace Umbraco.Commerce.Checkout.Events
1623
{
17-
public class SyncZeroValuePaymentProviderContinueUrl : INotificationHandler<ContentCacheRefresherNotification>
24+
public class SyncZeroValuePaymentProviderContinueUrl : INotificationAsyncHandler<ContentCacheRefresherNotification>
1825
{
19-
public void Handle(ContentCacheRefresherNotification notification)
26+
private readonly IUmbracoContextFactory _umbracoContextFactory;
27+
private readonly IUmbracoCommerceApi _commerceApi;
28+
private readonly IPublishedContentTypeCache _publishedContentTypeCacheService;
29+
private readonly IDocumentNavigationQueryService _documentNavigationQueryService;
30+
31+
public SyncZeroValuePaymentProviderContinueUrl(
32+
IUmbracoContextFactory umbracoContextFactory,
33+
IUmbracoCommerceApi commerceApi,
34+
IPublishedContentTypeCache publishedContentTypeCacheService,
35+
IDocumentNavigationQueryService documentNavigationQueryService)
2036
{
21-
Handle(notification.MessageObject, notification.MessageType);
37+
_umbracoContextFactory = umbracoContextFactory;
38+
_commerceApi = commerceApi;
39+
_publishedContentTypeCacheService = publishedContentTypeCacheService;
40+
_documentNavigationQueryService = documentNavigationQueryService;
2241
}
2342

24-
private IUmbracoContextFactory _umbracoContextFactory;
25-
private IUmbracoCommerceApi _commerceApi;
26-
27-
public SyncZeroValuePaymentProviderContinueUrl(IUmbracoContextFactory umbracoContextFactory,
28-
IUmbracoCommerceApi commerceApi)
43+
public Task HandleAsync(ContentCacheRefresherNotification notification, CancellationToken cancellationToken)
2944
{
30-
_umbracoContextFactory = umbracoContextFactory;
31-
_commerceApi = commerceApi;
45+
ArgumentNullException.ThrowIfNull(notification, nameof(notification));
46+
return HandleAsync(notification.MessageObject, notification.MessageType);
3247
}
3348

34-
public void Handle(object messageObject, MessageType messageType)
49+
public async Task HandleAsync(object messageObject, MessageType messageType)
3550
{
3651
if (messageType != MessageType.RefreshByPayload)
52+
{
3753
throw new NotSupportedException();
54+
}
3855

39-
var payloads = messageObject as ContentCacheRefresher.JsonPayload[];
40-
if (payloads == null)
56+
if (messageObject is not ContentCacheRefresher.JsonPayload[] payloads)
57+
{
4158
return;
59+
}
4260

43-
using (var ctx = _umbracoContextFactory.EnsureUmbracoContext())
61+
using (UmbracoContextReference ctx = _umbracoContextFactory.EnsureUmbracoContext())
4462
{
45-
foreach (var payload in payloads)
63+
foreach (ContentCacheRefresher.JsonPayload payload in payloads)
4664
{
4765
if (payload.ChangeTypes.HasType(TreeChangeTypes.RefreshNode))
4866
{
4967
// Single node refresh
50-
var node = ctx.UmbracoContext.Content.GetById(payload.Id);
68+
IPublishedContent? node = ctx.UmbracoContext.Content.GetById(payload.Id);
5169
if (node != null && IsConfirmationPageType(node))
5270
{
53-
DoSyncZeroValuePaymentProviderContinueUrl(node);
71+
await DoSyncZeroValuePaymentProviderContinueUrlAsync(node);
5472
}
5573
}
5674
else if (payload.ChangeTypes.HasType(TreeChangeTypes.RefreshBranch))
5775
{
5876
// Branch refresh
59-
var rootNode = ctx.UmbracoContext.Content.GetById(payload.Id);
77+
IPublishedContent? rootNode = ctx.UmbracoContext.Content.GetById(payload.Id);
6078
if (rootNode != null)
6179
{
62-
var nodeType = ctx.UmbracoContext.Content.GetContentType(UmbracoCommerceCheckoutConstants.ContentTypes.Aliases.CheckoutStepPage);
63-
if (nodeType == null)
80+
IPublishedContentType checkoutStepPageDocType = _publishedContentTypeCacheService.Get(PublishedItemType.Content, UmbracoCommerceCheckoutConstants.ContentTypes.Aliases.CheckoutStepPage);
81+
// TODO - Dinh: remove this line
82+
//IPublishedContentType? nodeType = ctx.UmbracoContext.Content.GetContentType(UmbracoCommerceCheckoutConstants.ContentTypes.Aliases.CheckoutStepPage);
83+
if (checkoutStepPageDocType == null)
84+
{
6485
continue;
86+
}
6587

66-
var nodes = ctx.UmbracoContext.Content.GetByContentType(nodeType);
67-
68-
foreach (var node in nodes?.Where(x => IsConfirmationPageType(x) && x.Path.StartsWith(rootNode.Path)))
88+
// TODO: fix the obsolete warning. Try using INavigationQueryService
89+
IEnumerable<IPublishedContent> nodes = ctx.UmbracoContext.Content.GetByContentType(checkoutStepPageDocType);
90+
IEnumerable<IPublishedContent> confimationPages = nodes?.Where(x => IsConfirmationPageType(x) && x.Path.StartsWith(rootNode.Path, StringComparison.Ordinal)) ?? [];
91+
foreach (IPublishedContent? node in confimationPages)
6992
{
70-
DoSyncZeroValuePaymentProviderContinueUrl(node);
93+
await DoSyncZeroValuePaymentProviderContinueUrlAsync(node);
7194
}
7295
}
7396
}
7497
else if (payload.ChangeTypes.HasType(TreeChangeTypes.RefreshAll))
7598
{
7699
// All refresh
77-
var nodeType = ctx.UmbracoContext.Content.GetContentType(UmbracoCommerceCheckoutConstants.ContentTypes.Aliases.CheckoutStepPage);
78-
if (nodeType == null)
100+
// TODO - Dinh: remove this line
101+
//IPublishedContentType? nodeType = ctx.UmbracoContext.Content.GetContentType(UmbracoCommerceCheckoutConstants.ContentTypes.Aliases.CheckoutStepPage);
102+
IPublishedContentType checkoutStepPageDocType = _publishedContentTypeCacheService.Get(PublishedItemType.Content, UmbracoCommerceCheckoutConstants.ContentTypes.Aliases.CheckoutStepPage);
103+
if (checkoutStepPageDocType == null)
104+
{
79105
continue;
106+
}
80107

81-
var nodes = ctx.UmbracoContext.Content.GetByContentType(nodeType);
82-
83-
foreach (var node in nodes?.Where(x => IsConfirmationPageType(x)))
108+
// TODO: fix the obsolete warning. Try using INavigationQueryService
109+
IEnumerable<IPublishedContent> nodes = ctx.UmbracoContext.Content.GetByContentType(checkoutStepPageDocType);
110+
IEnumerable<IPublishedContent> confimationPages = nodes?.Where(IsConfirmationPageType) ?? [];
111+
foreach (IPublishedContent? node in confimationPages)
84112
{
85-
DoSyncZeroValuePaymentProviderContinueUrl(node);
113+
await DoSyncZeroValuePaymentProviderContinueUrlAsync(node);
86114
}
87115
}
88116
}
89117
}
90118
}
91119

92-
private bool IsConfirmationPageType(IPublishedContent node)
120+
private static bool IsConfirmationPageType(IPublishedContent node)
93121
{
94122
if (node == null || node.ContentType == null || !node.HasProperty("uccStepType"))
123+
{
95124
return false;
125+
}
96126

97127
return node.ContentType.Alias == UmbracoCommerceCheckoutConstants.ContentTypes.Aliases.CheckoutStepPage && node.Value<string>("uccStepType") == "Confirmation";
98128
}
99129

100-
private void DoSyncZeroValuePaymentProviderContinueUrl(IPublishedContent confirmationNode)
130+
private async Task DoSyncZeroValuePaymentProviderContinueUrlAsync(IPublishedContent confirmationNode)
101131
{
102132
if (confirmationNode == null)
103133
{
104134
return;
105135
}
106136

107-
StoreReadOnly? store = confirmationNode.GetStore();
108-
if (store == null)
109-
{
110-
return;
111-
}
112-
113-
PaymentMethodReadOnly paymentMethod = _commerceApi.GetPaymentMethod(store.Id, UmbracoCommerceCheckoutConstants.PaymentMethods.Aliases.ZeroValue);
137+
StoreReadOnly store = confirmationNode.GetStore();
138+
PaymentMethodReadOnly paymentMethod = await _commerceApi.GetPaymentMethodAsync(store.Id, UmbracoCommerceCheckoutConstants.PaymentMethods.Aliases.ZeroValue);
114139
if (paymentMethod == null)
115140
{
116141
return;
117142
}
118143

119-
_commerceApi.Uow.Execute(uow =>
144+
await _commerceApi.Uow.ExecuteAsync(async uow =>
120145
{
121-
PaymentMethod writable = paymentMethod.AsWritable(uow)
122-
.SetSetting("ContinueUrl", confirmationNode.Url());
146+
PaymentMethod writable = await paymentMethod.AsWritableAsync(uow)
147+
.SetSettingAsync("ContinueUrl", confirmationNode.Url());
123148

124-
_commerceApi.SavePaymentMethod(writable);
149+
await _commerceApi.SavePaymentMethodAsync(writable);
125150

126151
uow.Complete();
127152
});

src/Umbraco.Commerce.Checkout/Extensions/CompositionExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static IBuilder AddUmbracoCommerceEventHandlers(this IBuilder builder)
4141
public static IBuilder AddUmbracoCommerceInstallPipeline(this IBuilder builder)
4242
{
4343
IUmbracoCommerceBuilder commerceBuilder = builder.WithUmbracoCommerceBuilder();
44-
commerceBuilder.WithAsyncPipeline<InstallAsyncPipelineTask, InstallPipelineContext>()
44+
commerceBuilder.WithPipeline<InstallAsyncPipelineTask, InstallPipelineContext>()
4545
.Add<CreateUmbracoCommerceCheckoutDataTypesTask>()
4646
.Add<CreateUmbracoCommerceCheckoutDocumentTypesTask>()
4747
.Add<CreateUmbracoCommerceCheckoutNodesTask>()

src/Umbraco.Commerce.Checkout/Pipeline/InstallAsyncPipelineTask.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44

55
namespace Umbraco.Commerce.Checkout.Pipeline
66
{
7-
public class InstallAsyncPipelineTask : AsyncPipelineTaskCollection<InstallPipelineContext>
7+
public class InstallAsyncPipelineTask(Func<IEnumerable<IAsyncPipelineTask<InstallPipelineContext>>> items) : PipelineTaskCollection<InstallPipelineContext>(items)
88
{
9-
public InstallAsyncPipelineTask(Func<IEnumerable<IAsyncPipelineTask<InstallPipelineContext>>> items)
10-
: base(items)
11-
{
12-
}
139
}
1410
}

0 commit comments

Comments
 (0)