Skip to content

Commit

Permalink
Handle shopping cart corruption.
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahelsaig committed Dec 29, 2023
1 parent 42f82c4 commit 29f236e
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,22 @@ await _notifier.ErrorAsync(H["You have to accept cookies in your browser to add
public async Task<ActionResult> Update(ShoppingCartUpdateModel cart, string shoppingCartId)
{
var updatedLines = new List<ShoppingCartLineUpdateModel>();
foreach (var line in cart.Lines)

var lines = await cart.Lines.AwaitEachAsync(async line =>
(Line: line, Item: await _shoppingCartSerializer.ParseCartLineAsync(line)));

if (lines.Any(line => line.Item == null))
{
await _shoppingCartPersistence.StoreAsync(new ShoppingCart(), shoppingCartId);

await _notifier.ErrorAsync(
H["Your shopping cart is broken and had to be replaced. We apologize for the inconvenience."]);
return RedirectToAction(nameof(Empty));
}

foreach (var (line, item) in lines)
{
var isValid = true;
var item = await _shoppingCartSerializer.ParseCartLineAsync(line);

await _workflowManagers.TriggerEventAsync<CartUpdatedEvent>(
new { LineItem = item },
Expand Down

0 comments on commit 29f236e

Please sign in to comment.