Skip to content

Commit 502753f

Browse files
Cleanup
1 parent 79511c5 commit 502753f

16 files changed

+179
-203
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
##
44
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
55

6+
# Jetbrains
7+
.idea
8+
69
# User-specific files
710
*.rsuser
811
*.suo

src/Umbraco.Commerce.Checkout/Composing/UmbracoCommerceCheckoutComposer.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@ namespace Umbraco.Commerce.Checkout.Composing
88
public class UmbracoCommerceCheckoutComposer : IComposer
99
{
1010
public void Compose(IBuilder builder)
11-
{
1211
// If Umbraco Commerce Checkout hasn't been added manually by now,
1312
// add it automatically with the default configuration.
14-
// If Umbraco Commerce Checkout has already been added manully, then
13+
// If Umbraco Commerce Checkout has already been added manually, then
1514
// the AddUmbracoCommerceCheckout() call will just exit early.
16-
builder.AddUmbracoCommerceCheckout();
17-
}
15+
=> builder.AddUmbracoCommerceCheckout();
1816
}
1917
}

src/Umbraco.Commerce.Checkout/Configuration/UmbracoCommerceCheckoutSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ namespace Umbraco.Commerce.Checkout.Configuration
22
{
33
public class UmbracoCommerceCheckoutSettings
44
{
5-
public bool ResetPaymentMethodOnShippingMethodChange { get; set; }
5+
// public bool ResetPaymentMethodOnShippingMethodChange { get; set; }
66
}
77
}
Lines changed: 91 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,91 @@
1-
using System.Threading.Tasks;
2-
using Microsoft.Extensions.Options;
3-
using Umbraco.Commerce.Checkout.Configuration;
4-
using Umbraco.Commerce.Common.Events;
5-
using Umbraco.Commerce.Core.Events.Notification;
6-
7-
namespace Umbraco.Commerce.Checkout.Events
8-
{
9-
// In this store configuration, if someone goes through the checkout flow
10-
// but then back tracks and modifies the order or previous checkout details
11-
// then we'll keep clearing out the steps ahead so that the order calculation
12-
// doesn't show a potential incorrect calculation should the options previously
13-
// selected no longer be available because of the changes made.
14-
15-
public class OrderProductAddingHandler : NotificationEventHandlerBase<OrderProductAddingNotification>
16-
{
17-
public override async Task HandleAsync(OrderProductAddingNotification evt)
18-
{
19-
if (!evt.Order.IsFinalized)
20-
{
21-
_ = await evt.Order.ClearShippingMethodAsync();
22-
_ = await evt.Order.ClearPaymentMethodAsync();
23-
}
24-
}
25-
}
26-
27-
public class OrderLineChangingHandler : NotificationEventHandlerBase<OrderLineChangingNotification>
28-
{
29-
public override async Task HandleAsync(OrderLineChangingNotification evt)
30-
{
31-
if (!evt.Order.IsFinalized)
32-
{
33-
_ = await evt.Order.ClearShippingMethodAsync();
34-
_ = await evt.Order.ClearPaymentMethodAsync();
35-
}
36-
}
37-
}
38-
39-
public class OrderLineRemovingHandler : NotificationEventHandlerBase<OrderLineRemovingNotification>
40-
{
41-
public override async Task HandleAsync(OrderLineRemovingNotification evt)
42-
{
43-
if (!evt.Order.IsFinalized)
44-
{
45-
_ = await evt.Order.ClearShippingMethodAsync();
46-
_ = await evt.Order.ClearPaymentMethodAsync();
47-
}
48-
}
49-
}
50-
51-
public class OrderPaymentCountryRegionChangingHandler : NotificationEventHandlerBase<OrderPaymentCountryRegionChangingNotification>
52-
{
53-
public override async Task HandleAsync(OrderPaymentCountryRegionChangingNotification evt)
54-
{
55-
if (!evt.Order.IsFinalized)
56-
{
57-
_ = await evt.Order.ClearPaymentMethodAsync();
58-
}
59-
}
60-
}
61-
62-
public class OrderShippingCountryRegionChangingHandler : NotificationEventHandlerBase<OrderShippingCountryRegionChangingNotification>
63-
{
64-
public override async Task HandleAsync(OrderShippingCountryRegionChangingNotification evt)
65-
{
66-
if (!evt.Order.IsFinalized)
67-
{
68-
_ = await evt.Order.ClearShippingMethodAsync();
69-
_ = await evt.Order.ClearPaymentMethodAsync();
70-
}
71-
}
72-
}
73-
74-
public class OrderShippingMethodChangingHandler : NotificationEventHandlerBase<OrderShippingMethodChangingNotification>
75-
{
76-
private readonly UmbracoCommerceCheckoutSettings _settings;
77-
78-
public OrderShippingMethodChangingHandler(IOptions<UmbracoCommerceCheckoutSettings> settings)
79-
{
80-
_settings = settings.Value;
81-
}
82-
83-
public override async Task HandleAsync(OrderShippingMethodChangingNotification evt)
84-
{
85-
if (!evt.Order.IsFinalized && _settings.ResetPaymentMethodOnShippingMethodChange)
86-
{
87-
_ = await evt.Order.ClearPaymentMethodAsync();
88-
}
89-
}
90-
}
91-
}
1+
// using System.Threading.Tasks;
2+
// using Microsoft.Extensions.Options;
3+
// using Umbraco.Commerce.Checkout.Configuration;
4+
// using Umbraco.Commerce.Common.Events;
5+
// using Umbraco.Commerce.Core.Events.Notification;
6+
//
7+
// namespace Umbraco.Commerce.Checkout.Events
8+
// {
9+
// // In this store configuration, if someone goes through the checkout flow
10+
// // but then back tracks and modifies the order or previous checkout details
11+
// // then we'll keep clearing out the steps ahead so that the order calculation
12+
// // doesn't show a potential incorrect calculation should the options previously
13+
// // selected no longer be available because of the changes made.
14+
//
15+
// public class OrderProductAddingHandler : NotificationEventHandlerBase<OrderProductAddingNotification>
16+
// {
17+
// public override async Task HandleAsync(OrderProductAddingNotification evt)
18+
// {
19+
// if (!evt.Order.IsFinalized)
20+
// {
21+
// await evt.Order.ClearShippingMethodAsync();
22+
// await evt.Order.ClearPaymentMethodAsync();
23+
// }
24+
// }
25+
// }
26+
//
27+
// public class OrderLineChangingHandler : NotificationEventHandlerBase<OrderLineChangingNotification>
28+
// {
29+
// public override async Task HandleAsync(OrderLineChangingNotification evt)
30+
// {
31+
// if (!evt.Order.IsFinalized)
32+
// {
33+
// await evt.Order.ClearShippingMethodAsync();
34+
// await evt.Order.ClearPaymentMethodAsync();
35+
// }
36+
// }
37+
// }
38+
//
39+
// public class OrderLineRemovingHandler : NotificationEventHandlerBase<OrderLineRemovingNotification>
40+
// {
41+
// public override async Task HandleAsync(OrderLineRemovingNotification evt)
42+
// {
43+
// if (!evt.Order.IsFinalized)
44+
// {
45+
// await evt.Order.ClearShippingMethodAsync();
46+
// await evt.Order.ClearPaymentMethodAsync();
47+
// }
48+
// }
49+
// }
50+
//
51+
// public class OrderPaymentCountryRegionChangingHandler : NotificationEventHandlerBase<OrderPaymentCountryRegionChangingNotification>
52+
// {
53+
// public override async Task HandleAsync(OrderPaymentCountryRegionChangingNotification evt)
54+
// {
55+
// if (!evt.Order.IsFinalized)
56+
// {
57+
// await evt.Order.ClearPaymentMethodAsync();
58+
// }
59+
// }
60+
// }
61+
//
62+
// public class OrderShippingCountryRegionChangingHandler : NotificationEventHandlerBase<OrderShippingCountryRegionChangingNotification>
63+
// {
64+
// public override async Task HandleAsync(OrderShippingCountryRegionChangingNotification evt)
65+
// {
66+
// if (!evt.Order.IsFinalized)
67+
// {
68+
// await evt.Order.ClearShippingMethodAsync();
69+
// await evt.Order.ClearPaymentMethodAsync();
70+
// }
71+
// }
72+
// }
73+
//
74+
// public class OrderShippingMethodChangingHandler : NotificationEventHandlerBase<OrderShippingMethodChangingNotification>
75+
// {
76+
// private readonly UmbracoCommerceCheckoutSettings _settings;
77+
//
78+
// public OrderShippingMethodChangingHandler(IOptions<UmbracoCommerceCheckoutSettings> settings)
79+
// {
80+
// _settings = settings.Value;
81+
// }
82+
//
83+
// public override async Task HandleAsync(OrderShippingMethodChangingNotification evt)
84+
// {
85+
// if (!evt.Order.IsFinalized && _settings.ResetPaymentMethodOnShippingMethodChange)
86+
// {
87+
// await evt.Order.ClearPaymentMethodAsync();
88+
// }
89+
// }
90+
// }
91+
// }

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

Lines changed: 43 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Linq;
43
using System.Threading;
54
using System.Threading.Tasks;
6-
using Umbraco.Cms.Core;
75
using Umbraco.Cms.Core.Cache;
86
using Umbraco.Cms.Core.Events;
97
using Umbraco.Cms.Core.Models.PublishedContent;
@@ -12,7 +10,6 @@
1210
using Umbraco.Cms.Core.Services.Changes;
1311
using Umbraco.Cms.Core.Services.Navigation;
1412
using Umbraco.Cms.Core.Sync;
15-
using Umbraco.Cms.Core.Web;
1613
using Umbraco.Commerce.Checkout.Web;
1714
using Umbraco.Commerce.Core.Api;
1815
using Umbraco.Commerce.Core.Models;
@@ -23,94 +20,81 @@ namespace Umbraco.Commerce.Checkout.Events
2320
{
2421
public class SyncZeroValuePaymentProviderContinueUrl : INotificationAsyncHandler<ContentCacheRefresherNotification>
2522
{
26-
private readonly IUmbracoContextFactory _umbracoContextFactory;
2723
private readonly IUmbracoCommerceApi _commerceApi;
24+
private readonly INavigationQueryService _navigationQueryService;
25+
private readonly IPublishedContentCache _publishedContentCacheService;
2826
private readonly IPublishedContentTypeCache _publishedContentTypeCacheService;
29-
private readonly IDocumentNavigationQueryService _documentNavigationQueryService;
3027

3128
public SyncZeroValuePaymentProviderContinueUrl(
32-
IUmbracoContextFactory umbracoContextFactory,
3329
IUmbracoCommerceApi commerceApi,
34-
IPublishedContentTypeCache publishedContentTypeCacheService,
35-
IDocumentNavigationQueryService documentNavigationQueryService)
30+
INavigationQueryService navigationQueryService,
31+
IPublishedContentCache publishedContentCacheService,
32+
IPublishedContentTypeCache publishedContentTypeCacheService)
3633
{
37-
_umbracoContextFactory = umbracoContextFactory;
3834
_commerceApi = commerceApi;
35+
_navigationQueryService = navigationQueryService;
36+
_publishedContentCacheService = publishedContentCacheService;
3937
_publishedContentTypeCacheService = publishedContentTypeCacheService;
40-
_documentNavigationQueryService = documentNavigationQueryService;
4138
}
4239

43-
public Task HandleAsync(ContentCacheRefresherNotification notification, CancellationToken cancellationToken)
40+
public async Task HandleAsync(ContentCacheRefresherNotification notification, CancellationToken cancellationToken)
4441
{
4542
ArgumentNullException.ThrowIfNull(notification, nameof(notification));
46-
return HandleAsync(notification.MessageObject, notification.MessageType);
47-
}
4843

49-
public async Task HandleAsync(object messageObject, MessageType messageType)
50-
{
51-
if (messageType != MessageType.RefreshByPayload)
44+
if (notification.MessageType != MessageType.RefreshByPayload)
5245
{
5346
throw new NotSupportedException();
5447
}
5548

56-
if (messageObject is not ContentCacheRefresher.JsonPayload[] payloads)
49+
if (notification.MessageObject is not ContentCacheRefresher.JsonPayload[] payloads)
5750
{
5851
return;
5952
}
6053

61-
using (UmbracoContextReference ctx = _umbracoContextFactory.EnsureUmbracoContext())
54+
foreach (ContentCacheRefresher.JsonPayload payload in payloads)
6255
{
63-
foreach (ContentCacheRefresher.JsonPayload payload in payloads)
56+
if (payload.ChangeTypes.HasType(TreeChangeTypes.RefreshNode))
6457
{
65-
if (payload.ChangeTypes.HasType(TreeChangeTypes.RefreshNode))
58+
// Single node refresh
59+
IPublishedContent? node = _publishedContentCacheService.GetById(payload.Id);
60+
if (node != null && IsConfirmationPageType(node))
6661
{
67-
// Single node refresh
68-
IPublishedContent? node = ctx.UmbracoContext.Content.GetById(payload.Id);
69-
if (node != null && IsConfirmationPageType(node))
70-
{
71-
await DoSyncZeroValuePaymentProviderContinueUrlAsync(node);
72-
}
62+
await DoSyncZeroValuePaymentProviderContinueUrlAsync(node);
7363
}
74-
else if (payload.ChangeTypes.HasType(TreeChangeTypes.RefreshBranch))
64+
}
65+
else if (payload.ChangeTypes.HasType(TreeChangeTypes.RefreshBranch))
66+
{
67+
// Branch refresh
68+
IPublishedContent? rootNode = _publishedContentCacheService.GetById(payload.Id);
69+
if (rootNode != null && _navigationQueryService.TryGetDescendantsKeysOfType(rootNode.Key, UmbracoCommerceCheckoutConstants.ContentTypes.Aliases.CheckoutStepPage, out IEnumerable<Guid> keys))
7570
{
76-
// Branch refresh
77-
IPublishedContent? rootNode = ctx.UmbracoContext.Content.GetById(payload.Id);
78-
if (rootNode != null)
71+
foreach (Guid key in keys)
7972
{
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-
{
85-
continue;
86-
}
87-
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)
73+
IPublishedContent? node = _publishedContentCacheService.GetById(key);
74+
if (node != null && IsConfirmationPageType(node))
9275
{
9376
await DoSyncZeroValuePaymentProviderContinueUrlAsync(node);
9477
}
9578
}
9679
}
97-
else if (payload.ChangeTypes.HasType(TreeChangeTypes.RefreshAll))
80+
}
81+
else if (payload.ChangeTypes.HasType(TreeChangeTypes.RefreshAll))
82+
{
83+
if (_navigationQueryService.TryGetRootKeys(out IEnumerable<Guid> rootKeys))
9884
{
99-
// All refresh
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)
85+
foreach (Guid rootKey in rootKeys)
10486
{
105-
continue;
106-
}
107-
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)
112-
{
113-
await DoSyncZeroValuePaymentProviderContinueUrlAsync(node);
87+
if (_navigationQueryService.TryGetDescendantsKeysOfType(rootKey, UmbracoCommerceCheckoutConstants.ContentTypes.Aliases.CheckoutStepPage, out IEnumerable<Guid> keys))
88+
{
89+
foreach (Guid key in keys)
90+
{
91+
IPublishedContent? node = _publishedContentCacheService.GetById(key);
92+
if (node != null && IsConfirmationPageType(node))
93+
{
94+
await DoSyncZeroValuePaymentProviderContinueUrlAsync(node);
95+
}
96+
}
97+
}
11498
}
11599
}
116100
}
@@ -119,7 +103,7 @@ public async Task HandleAsync(object messageObject, MessageType messageType)
119103

120104
private static bool IsConfirmationPageType(IPublishedContent node)
121105
{
122-
if (node == null || node.ContentType == null || !node.HasProperty("uccStepType"))
106+
if (!node.HasProperty("uccStepType"))
123107
{
124108
return false;
125109
}
@@ -129,13 +113,9 @@ private static bool IsConfirmationPageType(IPublishedContent node)
129113

130114
private async Task DoSyncZeroValuePaymentProviderContinueUrlAsync(IPublishedContent confirmationNode)
131115
{
132-
if (confirmationNode == null)
133-
{
134-
return;
135-
}
136-
137116
StoreReadOnly store = confirmationNode.GetStore();
138117
PaymentMethodReadOnly paymentMethod = await _commerceApi.GetPaymentMethodAsync(store.Id, UmbracoCommerceCheckoutConstants.PaymentMethods.Aliases.ZeroValue);
118+
139119
if (paymentMethod == null)
140120
{
141121
return;

0 commit comments

Comments
 (0)