You are here

private function CSVUpdateForm::loadProductByIndex in Commerce Smart Importer 8

Loads product.

1 call to CSVUpdateForm::loadProductByIndex()
CSVUpdateForm::readCsvProductsToUpdate in src/Form/CSVUpdateForm.php
Reads and formats products for update.

File

src/Form/CSVUpdateForm.php, line 499

Class

CSVUpdateForm
Class CSVUpdateForm.

Namespace

Drupal\commerce_smart_importer\Form

Code

private function loadProductByIndex($field_definitions, $identifier_index, $line, $variation) {
  if (empty($identifier_index)) {
    return FALSE;
  }
  $entity = FALSE;
  if (in_array('variation', $identifier_index) && $variation !== FALSE) {
    $entity = $variation
      ->getProduct();
  }
  if (empty($entity)) {
    foreach ($identifier_index as $index) {
      if (is_numeric($index) && $field_definitions[$index]['machine_names'] == 'product_id') {
        if (empty($line[$field_definitions[$index]['index']])) {
          return FALSE;
        }
        $entity = Product::load($line[$field_definitions[$index]['index']]);
      }
    }
  }
  if (empty($entity)) {
    $this
      ->messenger()
      ->addStatus($this
      ->t('Could not identify product with') . ' ' . $line[$field_definitions[$index]['index']]);
  }
  return !empty($entity) ? $entity : FALSE;
}