private function CSVUpdateForm::loadVariationByIndex in Commerce Smart Importer 8
Loads variation.
1 call to CSVUpdateForm::loadVariationByIndex()
- CSVUpdateForm::readCsvProductsToUpdate in src/
Form/ CSVUpdateForm.php - Reads and formats products for update.
File
- src/
Form/ CSVUpdateForm.php, line 527
Class
- CSVUpdateForm
- Class CSVUpdateForm.
Namespace
Drupal\commerce_smart_importer\FormCode
private function loadVariationByIndex($field_definitions, $identifier_index, $line) {
if (empty($identifier_index)) {
return FALSE;
}
$entity = FALSE;
foreach ($identifier_index as $index) {
if ($field_definitions[$index]['machine_names'] == 'sku') {
$id = $this->smartImporterService
->getVariationIdBySku(trim($line[$field_definitions[$index]['index']]));
if ($id !== FALSE) {
$entity = ProductVariation::load($id);
if (!empty($entity)) {
return $entity;
}
}
}
elseif ($field_definitions[$index]['machine_names'] == 'variation_id') {
$entity = ProductVariation::load(trim($line[$field_definitions[$index]['index']]));
if (!empty($entity)) {
return $entity;
}
}
}
if (empty($entity)) {
$this
->messenger()
->addStatus($this
->t('Could not identify variation with') . ' ' . $line[$field_definitions[$index]['index']]);
}
return !empty($entity) ? $entity : FALSE;
}