Score:0

How to save a customer profile to address book in Drupal Commerce using JSON:API

ng flag

In the commerce order checkout page, if you use "Save to my address book" checkbox in the billing address section, the address is getting saved to the user's address book. But if I am doing this using JSON request, how can I save the address to the user's address book and how can I load the saved addresses.

Score:0
it flag

How you save depends somewhat on your desired UX. If you look at the code in the BillingInformation checkout pane (in the checkout module) or the CustomerProfile inline form plugin (in the order module), you'll see some properties used to instruct Commerce how and when to copy addresses to the addressbook.

If it's fine for your addresses to be copied when the order is placed (i.e. not immediately upon them being entered on a checkout form), then you can simply get by with setting copy_to_address_book in the profile's data array to TRUE. This will get picked up by the AddressBookSubscriber (in the order module), resulting in the address being copied to the user's addressbook upon order placement.

Other options would be discoverable through the way the checkout pane functions. There is no way, as far as I know, to trigger an immediate copy merely by the save of the profile, but I haven't looked deeply at Commerce API to confirm.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.