Skip to content

Commit 2cff8ad

Browse files
authored
OCC-178: User-friendly error if cookies can't be written and thus the shopping cart can't be managed (#333)
* Adding user-friendly error if cookies can't be written * Updating error message
1 parent 5292315 commit 2cff8ad

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/Modules/OrchardCore.Commerce/Controllers/ShoppingCartController.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using Lombiq.HelpfulLibraries.OrchardCore.Workflow;
2+
using Microsoft.AspNetCore.Http.Features;
23
using Microsoft.AspNetCore.Mvc;
4+
using Microsoft.AspNetCore.Mvc.Localization;
35
using OrchardCore.Commerce.Abstractions;
46
using OrchardCore.Commerce.Activities;
57
using OrchardCore.Commerce.Exceptions;
@@ -23,21 +25,24 @@ public class ShoppingCartController : Controller
2325
private readonly IShoppingCartPersistence _shoppingCartPersistence;
2426
private readonly IShoppingCartSerializer _shoppingCartSerializer;
2527
private readonly IEnumerable<IWorkflowManager> _workflowManagers;
28+
private readonly IHtmlLocalizer<ShoppingCartController> H;
2629

2730
public ShoppingCartController(
2831
INotifier notifier,
2932
IShapeFactory shapeFactory,
3033
IShoppingCartHelpers shoppingCartHelpers,
3134
IShoppingCartPersistence shoppingCartPersistence,
3235
IShoppingCartSerializer shoppingCartSerializer,
33-
IEnumerable<IWorkflowManager> workflowManagers)
36+
IEnumerable<IWorkflowManager> workflowManagers,
37+
IHtmlLocalizer<ShoppingCartController> htmlLocalizer)
3438
{
3539
_notifier = notifier;
3640
_shapeFactory = shapeFactory;
3741
_shoppingCartHelpers = shoppingCartHelpers;
3842
_shoppingCartPersistence = shoppingCartPersistence;
3943
_shoppingCartSerializer = shoppingCartSerializer;
4044
_workflowManagers = workflowManagers;
45+
H = htmlLocalizer;
4146
}
4247

4348
[HttpGet]
@@ -84,7 +89,18 @@ public async Task<ActionResult> Index(string shoppingCartId = null)
8489

8590
[HttpGet]
8691
[Route("cart-empty")]
87-
public IActionResult Empty() => View();
92+
public async Task<ActionResult> Empty()
93+
{
94+
var trackingConsentFeature = HttpContext.Features.Get<ITrackingConsentFeature>();
95+
if (trackingConsentFeature?.CanTrack == false)
96+
{
97+
await _notifier.ErrorAsync(H["You have to accept cookies in your browser to add items to your shopping " +
98+
"cart. If you have privacy-related browser extensions like ad-blockers or cookie blockers, they " +
99+
"might be preventing the website from setting cookies, try disabling them."]);
100+
}
101+
102+
return View();
103+
}
88104

89105
[HttpPost]
90106
[ValidateAntiForgeryToken]

0 commit comments

Comments
 (0)