I have been following this guide to create an order
https://docs.drupalcommerce.org/commerce2/developer-guide/orders
$order = Drupalcommerce_orderEntityOrder::create([
'type' => 'custom_order_type',
'state' => 'draft',
'mail' => 'user@example.com',
'uid' => 1,
'ip_address' => '127.0.0.1',
'order_number' => '6',
'billing_profile' => $profile,
'store_id' => $store->id(),
'order_items' => [$order_item],
'placed' => time(),
]);
Here $profile is the saved profile of one of the users.
Once I programmatically change the order status to placed with this code
$order->getState()->applyTransitionById('place');
The order is placed and everything looks fine, except that the user profile is deleted for some reason. The address book of the user becomes empty. I think I am missing a step, Is there a way to preserve the address while placing the order?