diff --git a/src/Plugins/Nop.Plugin.Misc.Brevo/Services/MarketingAutomationManager.cs b/src/Plugins/Nop.Plugin.Misc.Brevo/Services/MarketingAutomationManager.cs index f518583eeb3..28544138eb3 100644 --- a/src/Plugins/Nop.Plugin.Misc.Brevo/Services/MarketingAutomationManager.cs +++ b/src/Plugins/Nop.Plugin.Misc.Brevo/Services/MarketingAutomationManager.cs @@ -252,11 +252,13 @@ public async Task HandleOrderCompletedEventAsync(Order order) ArgumentNullException.ThrowIfNull(order); var customer = await _customerService.GetCustomerByIdAsync(order.CustomerId); + var shippingAddress = await _addressService.GetAddressByIdAsync(order.ShippingAddressId ?? 0); + var billingAddress = await _addressService.GetAddressByIdAsync(order.BillingAddressId); try { //first, try to identify current customer - await _marketingAutomationHttpClient.RequestAsync(new IdentifyRequest { Email = customer.Email }); + await _marketingAutomationHttpClient.RequestAsync(new IdentifyRequest { Email = customer.Email ?? billingAddress.Email }); //get URL helper var urlHelper = _urlHelperFactory.GetUrlHelper(_actionContextAccessor.ActionContext); @@ -296,9 +298,6 @@ public async Task HandleOrderCompletedEventAsync(Order order) }; }).ToArrayAsync(); - var shippingAddress = await _addressService.GetAddressByIdAsync(order.ShippingAddressId ?? 0); - var billingAddress = await _addressService.GetAddressByIdAsync(order.BillingAddressId); - var shippingAddressData = new { firstname = shippingAddress?.FirstName, @@ -356,7 +355,7 @@ public async Task HandleOrderCompletedEventAsync(Order order) //create track event object var trackEvent = new TrackEventRequest { - Email = customer.Email, + Email = customer.Email ?? billingAddress.Email, EventName = BrevoDefaults.OrderCompletedEventName, EventData = new { id = $"cart:{shoppingCartGuid}", data = cartData } };