Skip to content

Commit

Permalink
OCC-178: User-friendly error if cookies can't be written and thus the…
Browse files Browse the repository at this point in the history
… shopping cart can't be managed (#333)

* Adding user-friendly error if cookies can't be written

* Updating error message
  • Loading branch information
DemeSzabolcs authored Sep 12, 2023
1 parent 5292315 commit 2cff8ad
Showing 1 changed file with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Lombiq.HelpfulLibraries.OrchardCore.Workflow;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Localization;
using OrchardCore.Commerce.Abstractions;
using OrchardCore.Commerce.Activities;
using OrchardCore.Commerce.Exceptions;
Expand All @@ -23,21 +25,24 @@ public class ShoppingCartController : Controller
private readonly IShoppingCartPersistence _shoppingCartPersistence;
private readonly IShoppingCartSerializer _shoppingCartSerializer;
private readonly IEnumerable<IWorkflowManager> _workflowManagers;
private readonly IHtmlLocalizer<ShoppingCartController> H;

public ShoppingCartController(
INotifier notifier,
IShapeFactory shapeFactory,
IShoppingCartHelpers shoppingCartHelpers,
IShoppingCartPersistence shoppingCartPersistence,
IShoppingCartSerializer shoppingCartSerializer,
IEnumerable<IWorkflowManager> workflowManagers)
IEnumerable<IWorkflowManager> workflowManagers,
IHtmlLocalizer<ShoppingCartController> htmlLocalizer)
{
_notifier = notifier;
_shapeFactory = shapeFactory;
_shoppingCartHelpers = shoppingCartHelpers;
_shoppingCartPersistence = shoppingCartPersistence;
_shoppingCartSerializer = shoppingCartSerializer;
_workflowManagers = workflowManagers;
H = htmlLocalizer;
}

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

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

return View();
}

[HttpPost]
[ValidateAntiForgeryToken]
Expand Down

0 comments on commit 2cff8ad

Please sign in to comment.