You are here

public function AddressBook::load in Commerce Core 8.2

Loads the customer's profile.

Takes the default profile, if found. Otherwise falls back to the newest published profile.

Primarily used for profile types which only allow a single profile per user.

Ensures that the loaded profile is available, by filtering it against $available_countries. If the loaded profile is not available, NULL will be returned instead.

Parameters

\Drupal\user\UserInterface $customer: The customer.

string $profile_type_id: The profile type ID.

array $available_countries: List of country codes. If empty, all countries will be available.

Return value

\Drupal\profile\Entity\ProfileInterface|null The profile, or NULL if none found.

Overrides AddressBookInterface::load

1 call to AddressBook::load()
AddressBook::copy in modules/order/src/AddressBook.php
Copies the profile to the customer's address book.

File

modules/order/src/AddressBook.php, line 110

Class

AddressBook

Namespace

Drupal\commerce_order

Code

public function load(UserInterface $customer, $profile_type_id, array $available_countries = []) {
  if ($customer
    ->isAnonymous()) {
    return NULL;
  }
  $profile = $this->profileStorage
    ->loadByUser($customer, $profile_type_id);
  if ($profile && !$this
    ->isAvailable($profile, $available_countries)) {
    $profile = NULL;
  }
  return $profile;
}