Customer's AddressID in Order Address table

Bart Lewandowski asked on May 24, 2018 14:07

Hi,
Can you point me into right direction?
I'm integrating Kentico with ERP (NAV 17) and I need to import orders into ERP. My API works fine apart of addresses. The problem is that since NAV's customer address list holds ID of Kentico's CustomerAddress for both-ways synchronization, The BillingAddressID and ShippingAddressID on Order header in Kentico don't relate to that ID, but to ID of line in OrderAddress table, which doesn't hold any tie to customer address table at all. Hence I have trouble to tie ERP address with incoming order address (I could use postcode instead to tie them, but they are not unique, so it would cause problems). I added the CustomerAddressID to the OrderAddress table, and I planned to create a custom class which would populate that field at the end of basket process during order creation, similar to the class for custom Discount and Prices calculations. Unfortunately since discount and prices were explained pretty good (which means: with examples :P) in documentation, addresses are not. I'm not sure which provider to use and what class I should change to make it working seamlessly.

Recent Answers


Suneel Jhangiani answered on May 25, 2018 20:14

Kentico stores the Addresses against the Order which is important since a customer may move and you would still want the older orders to show the original address.

Therefore, in your synchronization routine you should add a new record to the OrderAddress table for each order and then set the OrderBillingAddressID and OrderShippingAddressID to that newley inserted record.

// Gets the customer's address
AddressInfo customerAddress = AddressInfoProvider.GetAddresses()
                                                    .WhereEquals("AddressCustomerID", customer.CustomerID)
                                                    .FirstObject;

if (customerAddress != null)
{
    // Gets the data from the customer's address
    orderBillingAddress = OrderAddressInfoProvider.CreateOrderAddressInfo(customerAddress);
    orderShippingAddress = orderBillingAddress ;

    // Sets the order addresses
    OrderAddressInfoProvider.SetAddressInfo(orderBillingAddress);
}

Since you mention both-way synchronization, you would have to consider what happens if a Customer Address is changed in Kentico as I presume that will update the record in the ERP and in turn change all the Old Orders to show new address details.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.