At what point of the chain is the best place to save the shipping address against the authenticated customer? I've tried hooking into the Invoice Created event but to no avail. It seems as though the CustomerKey is always null.
My code is as follows...
private void InvoiceService_Created(IInvoiceService sender, Merchello.Core.Events.NewEventArgs<IInvoice> newEventArgs)
{
if (!newEventArgs.Entity.CustomerKey.HasValue)
return;
var shippingAddress = newEventArgs.Entity.GetShippingAddresses().FirstOrDefault();
if (shippingAddress == null)
return;
var customer = MerchelloContext.Current.Services.CustomerService.GetByKey(newEventArgs.Entity.CustomerKey.Value);
if (customer == null)
return;
var exists = customer.Addresses.Any(x => x.AddressType == AddressType.Shipping && x.PostalCode.Equals(shippingAddress.PostalCode, StringComparison.InvariantCultureIgnoreCase));
if (exists)
return;
var address = customer.CreateCustomerAddress(shippingAddress, string.Empty, AddressType.Shipping);
customer.SaveCustomerAddress(address);
}
Save Shipping Address to Customer after an order
Hi
At what point of the chain is the best place to save the shipping address against the authenticated customer? I've tried hooking into the Invoice Created event but to no avail. It seems as though the CustomerKey is always null.
My code is as follows...
Thanks, Sam
is working on a reply...