40 lines
1.5 KiB
C#
40 lines
1.5 KiB
C#
using FruitBank.Common.Dtos;
|
|
using Nop.Core.Domain.Common;
|
|
|
|
namespace Nop.Plugin.Misc.FruitBankPlugin.Services;
|
|
|
|
/// <summary>
|
|
/// Builds the frozen <see cref="OrderSiteSnapshot"/> for an order from a customer
|
|
/// Address. Shaped to the NAV EKÁER LocationType (UnloadLocation). Stateless — used
|
|
/// by both the OrderPlacedEvent auto-assign and the manual save endpoint.
|
|
/// </summary>
|
|
public static class OrderSiteSnapshotBuilder
|
|
{
|
|
public static OrderSiteSnapshot FromAddress(Address a, string? customerVatNumber)
|
|
{
|
|
var name = !string.IsNullOrWhiteSpace(a.Company)
|
|
? a.Company
|
|
: $"{a.FirstName} {a.LastName}".Trim();
|
|
|
|
var street = string.Join(" ", new[] { a.Address1, a.Address2 }
|
|
.Where(s => !string.IsNullOrWhiteSpace(s)));
|
|
|
|
var locality = $"{a.ZipPostalCode} {a.City}".Trim();
|
|
|
|
var display = string.Join(", ", new[] { name, street, locality }
|
|
.Where(s => !string.IsNullOrWhiteSpace(s)));
|
|
|
|
return new OrderSiteSnapshot
|
|
{
|
|
SourceAddressId = a.Id,
|
|
Name = string.IsNullOrWhiteSpace(name) ? null : name,
|
|
VatNumber = customerVatNumber,
|
|
CountryCode = "HU", // outgoing EKÁER is domestic; export would resolve a.CountryId
|
|
ZipCode = a.ZipPostalCode,
|
|
City = a.City,
|
|
Street = string.IsNullOrWhiteSpace(street) ? null : street,
|
|
Display = string.IsNullOrWhiteSpace(display) ? $"#{a.Id}" : display
|
|
};
|
|
}
|
|
}
|