You are here

public function CommerceSmartImporerService::getStore in Commerce Smart Importer 8

1 call to CommerceSmartImporerService::getStore()
CommerceSmartImporerService::formatField in src/Plugin/CommerceSmartImporerService.php
Formats one field value based on field settings.

File

src/Plugin/CommerceSmartImporerService.php, line 563
Main Commerce Smart Importer Service.

Class

CommerceSmartImporerService
This is main Commerce Smart Importer Service.

Namespace

Drupal\commerce_smart_importer\Plugin

Code

public function getStore($value) {
  if (is_numeric($value)) {
    $query = $this->database
      ->select('commerce_store_field_data', 'cs')
      ->fields('cs', [
      'store_id',
    ])
      ->condition('cs.store_id', $value)
      ->range(0, 1)
      ->execute();
    $store_ids = $query
      ->fetchAll();
    if (count($store_ids) > 0) {
      return [
        'target_id' => reset($store_ids)->store_id,
      ];
    }
  }
  $query = $this->database
    ->select('commerce_store_field_data', 'cs')
    ->fields('cs', [
    'store_id',
    'name',
  ])
    ->condition('cs.name', $value)
    ->range(0, 1)
    ->execute();
  $store_ids = $query
    ->fetchAll();
  if (count($store_ids) > 0) {
    return [
      'target_id' => reset($store_ids)->store_id,
    ];
  }
  return '';
}