Hi DW,
We're working on an headless solution, and we're looking for a way to easily determine which address is used for customer(billing) address and delivery address,
and more importantly a way to compare the two.
Looking at our scenario:
We have to check if delivery address is the same as customer (billing) address
On the "Change" button, we have the option to select a different address or default address.
And in the future when we implement changing customer(billing) address, we'd have to compare the current customer address fields to information on "/dwapi/users/info" to see if it's the default address thats selected or not. But more on that in the end of this post.
Right now if you want to compare customer(billing) address and delivery address, you'd have to compare each field to determine if its the same address.
And if i want to change the delivery address or customer address to a existing address that i get via "/dwapi/users/addresses", i'd have to set each field in the request, which per say is fine.
But since we have access to the address id's in the "/dwapi/users/addresses" list, it would be easier if it was possible to change the addresses on the cart with two new fields, DeliveryAddressId and CustomerAddressId.
Looking at a snippet of the cart before anything changes has been made, so default customer address with no delivery address.
And a list of available addresses via "/dwapi/users/addresses".
A new way to populate delivery address, would be to just use the address id, ex:
make a PATCH call to /dwapi/ecommerce/carts/{secret}, with body of the DeliveryAddressId: {addressId}.
Like this:
And then the new cart would have the Id's populated, below has a snippet of a cart with the new fields.
Here i've just set CustomerAddressId to the CustomerUserId for an easy that to check if it's set to default.
But i guess that can be an issue if an actual address has the Id of the the UserId.
But now the DeliveryAddressId is set to 30, and it populated the Delivery address information accordingly.
And then we have an easy way to see if customer address is the same as delivery address, just by comparing CustomerAddressId and DeliveryAddressId.
Looking back at the address list, notice there is no default customer address in the "/dwapi/users/addresses" response.
So without this CustomerAddressId change, if we make any changes to customer address information, ex. changing customer address to be the same as delivery address with id 30, and then if we later want to reset it to default address, we'd have to fetch the original information from "/dwapi/users/info" and populate it that way. (at the moment we have that info in the user state and can use it from there, but it still requires a bit of work when you start from scratch).
But with this change, you could just say CustomerAddressId = 146 (CustomerUserId), and it would reset without having to get the information elsewhere.
And you get an easy way to check if the CustomerAddress has changed from default values aswell, since CustomerAddressId would be different from CustomerUserId or whatever the default value will be.
Ofc if you change the DeliveryAddress or CustomerAddress with the current way with populating each field in the PATCH body without using the Id's, it could just set to Id's to 0, showing that the address is'nt a saved one.
Looking forward to hear what you think.
Best regards,
Mikkel Hammer
Developer forum
E-mail notifications
Use address id to determine and change customer/delivery address on cart via DWAPI
Replies
Hi DW Care
Any news on this?
Best regards,
Mathias Gylden
bump
This is now devops#15658 - it has been put in queue to be done in 3 weeks.
Thanks Nicolai, sound great.
Looking forward to trying it out!
Best regards,
Mikkel Hammer
Hi Nicolai,
I can see that #15658 hasn't yet been implemented, so I would like to know if it can also be applied when submitting the cart through the templates?
Mario has been trying to reach out here https://doc.dynamicweb.com/forum/ecommerce-standard-features/ecommerce-standard-features/order-fields-with-addressid-not-getting-updated and we also looked into the source code and apparently it's simply not being recorded to the database.
I'm not advocating we'd want to simply submit the address id instead of the address fields (address, address2, ...) although it's nice to be able to do that instead, but at least storing the submitted value would help.
It would avoid custom development in some of our integrations where the ERP is expecting an address id rather than address strings. So we need store the address id, so when generating the XML to the ERP we get the corresponding address UID value.
Let me know if you have any questions.
Nuno Aguiar
Hi Nuno
Latest 9.16 have support for it - used in Swift, i.e. here: https://github.com/dynamicweb/Swift/blob/main/Swift/Files/Templates/Designs/Swift/eCom7/CartV2/Step/Helpers/AddressUser.cshtml#L168
The value is stored - at least according to code.
It is not in the webapi just yet
Oh, that's awesome news.
Can I then request that I have this quick turnaround for all of my future requests? I feel kind'of spoiled right now.
Hi Nicolai,
We were testing this on Swift v1.24 and we are seeting the value on the request, but the databse is not updated
https://cleanswift.mydwsite1.com/
DW 9.16.4, Swift v1.24
Request on checkoutPage
Database record
That would the regular cart - I have created a bugfix here: https://dev.azure.com/dynamicwebsoftware/Dynamicweb/_workitems/edit/16885
Hi
The bugfix regarding #16885 Save addressid to order when using regular cart
Now fixed in Dynamicweb version 9.16.6
Download release from here https://doc.dynamicweb.dk/downloads/dynamicweb-9
Sorry for any inconvenience this may have caused
Kind Regards
Dynamicweb Care Support
Kristian Kirkholt