You are here

class ImportingParameters in Commerce Smart Importer 8

Parameters what will be imported.

Hierarchy

Expanded class hierarchy of ImportingParameters

4 files declare their use of ImportingParameters
CommerceSmartImporerService.php in src/Plugin/CommerceSmartImporerService.php
Main Commerce Smart Importer Service.
CSVImportForm.php in src/Form/CSVImportForm.php
CSVUpdateForm.php in src/Form/CSVUpdateForm.php
OverrideController.php in src/Controller/OverrideController.php

File

src/ImportingParameters.php, line 8

Namespace

Drupal\commerce_smart_importer
View source
class ImportingParameters {

  /**
   * Indicates wheter or not fields with duplicate values will be imported.
   *
   * @var bool
   */
  public $duplicateValues = TRUE;

  /**
   * Indicates wheter or not fields with incorrect values will be imported.
   *
   * @var bool
   */
  public $incorrectValues = TRUE;

  /**
   * Import products with fields thats exceeds cardinality.
   *
   * @var bool
   */
  public $exceedsCardinality = TRUE;

  /**
   * Indicates wheter or not to import fields where default value will be used.
   *
   * @var bool
   */
  public $defaultValues = TRUE;

  /**
   * Update: indicates wheter or not images will be appended to current images.
   *
   * @var bool
   */
  public $appendImages = TRUE;

  /**
   * Import product with invalid variations.
   *
   * @var bool
   */
  public $notValidVariations = TRUE;

  /**
   * If this option is FALSE even perfect products will be skipped.
   *
   * @var bool
   */
  public $createProduct = TRUE;

  /**
   * If sku exists TRUE will generate new, FALSE will skip product.
   *
   * @var bool
   */
  public $sku = TRUE;

  /**
   * Disable all parameters.
   */
  public function disableAll() {
    $this->duplicateValues = FALSE;
    $this->incorrectValues = FALSE;
    $this->exceedsCardinality = FALSE;
    $this->defaultValues = FALSE;
    $this->notValidVariations = FALSE;
    $this->createProduct = FALSE;
    $this->sku = FALSE;
  }

  /**
   * Decide to create product or not.
   */
  public function matchParameters($field_logs) {
    if ($this->createProduct === FALSE) {
      return FALSE;
    }
    foreach ($field_logs as $field_log) {
      if ($field_log['required'] === FALSE) {
        return FALSE;
      }
      if ($this->defaultValues === FALSE && $field_log['default_value'] === FALSE) {
        return FALSE;
      }
      if ($this->exceedsCardinality === FALSE && $field_log['cardinality'] === FALSE) {
        return FALSE;
      }
      if ($this->duplicateValues === FALSE && $field_log['duplicates'] === FALSE) {
        return FALSE;
      }
      if ($this->incorrectValues === FALSE && count($field_log['not_valid'])) {
        return FALSE;
      }
      if (is_array($field_log) && array_key_exists('sku', $field_log)) {
        if ($this->sku === FALSE && count($field_log['not_valid'])) {
          return FALSE;
        }
      }
    }
    return TRUE;
  }

  /**
   * Decides if field should be createf based given parameters.
   */
  public function matchOneFieldLog($field_log) {
    if ($field_log['required'] === FALSE) {
      return FALSE;
    }
    if ($this->defaultValues === FALSE && $field_log['default_value'] === FALSE) {
      return FALSE;
    }
    if ($this->exceedsCardinality === FALSE && $field_log['cardinality'] === FALSE) {
      return FALSE;
    }
    if ($this->duplicateValues === FALSE && $field_log['duplicates'] === FALSE) {
      return FALSE;
    }
    if ($this->incorrectValues === FALSE && count($field_log['not_valid'])) {
      return FALSE;
    }
    return TRUE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ImportingParameters::$appendImages public property Update: indicates wheter or not images will be appended to current images.
ImportingParameters::$createProduct public property If this option is FALSE even perfect products will be skipped.
ImportingParameters::$defaultValues public property Indicates wheter or not to import fields where default value will be used.
ImportingParameters::$duplicateValues public property Indicates wheter or not fields with duplicate values will be imported.
ImportingParameters::$exceedsCardinality public property Import products with fields thats exceeds cardinality.
ImportingParameters::$incorrectValues public property Indicates wheter or not fields with incorrect values will be imported.
ImportingParameters::$notValidVariations public property Import product with invalid variations.
ImportingParameters::$sku public property If sku exists TRUE will generate new, FALSE will skip product.
ImportingParameters::disableAll public function Disable all parameters.
ImportingParameters::matchOneFieldLog public function Decides if field should be createf based given parameters.
ImportingParameters::matchParameters public function Decide to create product or not.