Skip to content

Commit

Permalink
OCC-208: Checkout exception if the Billing/ShippingAddressFieldEditor…
Browse files Browse the repository at this point in the history
… shapes are not present (#399)

* Preventing exception if an address field is null

* Conditionally filling out null address fields

* Update src/Modules/OrchardCore.Commerce.ContentFields/Drivers/AddressFieldDisplayDriver.cs

Co-authored-by: Hisham Bin Ateya <[email protected]>

* Removing unnecessary checks

* Updating comment

---------

Co-authored-by: Hisham Bin Ateya <[email protected]>
Co-authored-by: Sára El-Saig <[email protected]>
  • Loading branch information
3 people authored Jan 15, 2024
1 parent 655406e commit 1262a8f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,14 @@ bool IsRequiredFieldEmpty(string value, string key)
return true;
}

if (!await updater.TryUpdateModelAsync(viewModel, Prefix) ||
var updated = await updater.TryUpdateModelAsync(viewModel, Prefix);

if (viewModel.Address is null)
{
return await EditAsync(field, context);
}

if (!updated ||
IsRequiredFieldEmpty(viewModel.Address.Name, nameof(viewModel.Address.Name)) ||
IsRequiredFieldEmpty(viewModel.Address.StreetAddress1, nameof(viewModel.Address.StreetAddress1)) ||
IsRequiredFieldEmpty(viewModel.Address.City, nameof(viewModel.Address.City)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,22 @@ await order.AlterAsync<OrderPart>(async orderPart =>
orderPart.LineItems.SetItems(lineItems);
orderPart.Status.Text = OrderStatuses.Pending.HtmlClassify();
// When billing and shipping addresses are set to match and an address field is null, fill out its data
// with the other field's data. This is to properly store it in the order and display it on the order
// confirmation page.
if (orderPart.BillingAndShippingAddressesMatch.Value)
{
if (orderPart.BillingAddress.Address.Name is null)
{
orderPart.BillingAddress = orderPart.ShippingAddress;
}
if (orderPart.ShippingAddress.Address.Name is null)
{
orderPart.ShippingAddress = orderPart.BillingAddress;
}
}
await _orderEvents.AwaitEachAsync(orderEvents =>
orderEvents.CreatedFreeAsync(orderPart, cart, cartViewModel));
});
Expand Down

0 comments on commit 1262a8f

Please sign in to comment.