You are here

public function CommerceSmartImporerService::formatMultipleFieldValues in Commerce Smart Importer 8

Helper function for createNewProduct.

Formats multiple values.

2 calls to CommerceSmartImporerService::formatMultipleFieldValues()
CommerceSmartImporerService::createNewProduct in src/Plugin/CommerceSmartImporerService.php
Creates product.
CommerceSmartImporerService::updateProduct in src/Plugin/CommerceSmartImporerService.php
Updates entity with given values.

File

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

Class

CommerceSmartImporerService
This is main Commerce Smart Importer Service.

Namespace

Drupal\commerce_smart_importer\Plugin

Code

public function formatMultipleFieldValues($values, $field_definition, ImportingParameters $parameters, $external_folders) {
  $log['values'] = [];
  $log['not_valid'] = [];
  $log['has_log'] = FALSE;
  foreach ($values as $key => $value) {
    if ($value != '') {
      try {
        $log['values'][] = $this
          ->formatField($field_definition, $value, $external_folders, $parameters->createProduct);
      } catch (Exception $e) {
        $log['not_valid'][] = [
          'log' => $e
            ->getMessage(),
          'order' => $key + 1,
        ];
        $log['has_log'] = TRUE;
      }
    }
    elseif ($field_definition['machine_names'] == 'weight') {
      try {
        $log['values'][] = $this
          ->formatField($field_definition, '0 kg', $external_folders, $parameters->createProduct);
      } catch (Exception $e) {
        $log['not_valid'][] = [
          'log' => $e
            ->getMessage(),
          'order' => (string) ($key + 1),
        ];
        $log['has_log'] = TRUE;
      }
    }
  }
  return $log;
}