1

I'm using Drupal 8 with the module Commerce and I have an issue with the customer address.

I'm developing an export custom module in D8, and I'm stuck trying to load the profile (to access billing and shipping address) of a customer.

I'm not able to access this data from the custom module. And there is no documentation about the address pluggin ( https://www.drupal.org/project/address )

I have tried to load the order and the user data but there is no relevant field that helps me to achieve this.

Can anyone give me a hint?

Thanks in advance.

2

you can try get profile by order and can try the code below:

$order_id =1;
$entityManager = \Drupal::entityTypeManager();
$order = $entityManager->getStorage('commerce_order')->load($order_id);

get address by field billing_profile

$address = $order->billing_profile->entity->address->getValue();
| improve this answer | |
0

Since the customer profile is a content entity you can access customer profile information by using the entityTypeManager() function.

$entity_manager = \Drupal::entityTypeManager();
$profile = $entity_manager->getStorage('profile')->load($profile_id);
| improve this answer | |
  • 1
    It's worth noting that if you don't know the profile id and you're looking for the user profiles, try using $entity_manager->getStorage('profile')->loadByUser($account, 'customer', TRUE); and there's also loadMultipleByUser() and loadDefaultByUser(). – superdrupal Jun 21 '18 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.