You are here

public function Profile::query in Commerce Migrate 3.1.x

Same name and namespace in other branches
  1. 8.2 modules/commerce/src/Plugin/migrate/source/commerce1/Profile.php \Drupal\commerce_migrate_commerce\Plugin\migrate\source\commerce1\Profile::query()
  2. 3.0.x modules/commerce/src/Plugin/migrate/source/commerce1/Profile.php \Drupal\commerce_migrate_commerce\Plugin\migrate\source\commerce1\Profile::query()

Return value

\Drupal\Core\Database\Query\SelectInterface

Overrides SqlBase::query

File

modules/commerce/src/Plugin/migrate/source/commerce1/Profile.php, line 26

Class

Profile
Drupal 7 commerce_customer_profile source from database.

Namespace

Drupal\commerce_migrate_commerce\Plugin\migrate\source\commerce1

Code

public function query() {
  $query = $this
    ->select('commerce_customer_profile_revision', 'cpr')
    ->fields('cpr');
  $query
    ->innerJoin('commerce_customer_profile', 'cp', static::JOIN);
  $query
    ->fields('cp');
  $query
    ->addField('cpr', 'status', 'revision_status');
  $query
    ->addField('cpr', 'data', 'revision_data');

  /** @var \Drupal\Core\Database\Schema $db */
  if ($this
    ->getDatabase()
    ->schema()
    ->tableExists('commerce_addressbook_defaults')) {
    $query
      ->leftJoin('commerce_addressbook_defaults', 'cad', 'cp.profile_id = cad.profile_id AND cp.uid = cad.uid AND cp.type = cad.type');
    $query
      ->addField('cad', 'type', 'cad_type');
  }
  else {

    // If the currency column does not exist, add it as an expression to
    // normalize the query results.
    $query
      ->addExpression(':cad', 'cad_type', [
      ':cad' => FALSE,
    ]);
  }
  if (isset($this->configuration['profile_type'])) {
    $types = is_array($this->configuration['profile_type']) ? $this->configuration['profile_type'] : [
      $this->configuration['profile_type'],
    ];
    $query
      ->condition('cp.type', $types, 'IN');
  }
  return $query;
}