modules/acm_sku/src/ProductOptionsManager.php
protected function createProductOption($langcode, $option_id, $option_value, $attribute_id, $attribute_code, $weight) {
    if (strlen($option_value) == 0) {
      $this->logger->warning('Got empty value while syncing production options: @data', [
        '@data' => json_encode([
          'langcode' => $langcode,
          'option_id' => $option_id,
          'attribute_id' => $attribute_id,
          'attribute_code' => $attribute_code,
        ]),
      ]);

      return NULL;
    }

    // Update the term if already available.
    if ($term = $this->loadProductOptionByOptionId($attribute_code, $option_id, NULL, FALSE)) {
      $save_term = FALSE;

      // Save term even if weight changes.
      if ($term->getWeight() != $weight) {
        $save_term = TRUE;
      }

      if ($term->hasTranslation($langcode)) {
        $term = $term->getTranslation($langcode);

        // We won't allow editing name here, if required it must be done from
        // Magento.
        if ($term->getName() != $option_value) {
          $term->setName($option_value);
          $save_term = TRUE;
        }
      }
      else {
        $term = $term->addTranslation($langcode, []);
        $term->setName($option_value);
        $save_term = TRUE;
      }

      if ($save_term) {
        $term->setWeight($weight);
        $term->save();
      }
    }
    else {
      $term = $this->termStorage->create([
        'vid' => self::PRODUCT_OPTIONS_VOCABULARY,
        'langcode' => $langcode,
        'name' => $option_value,
        'weight' => $weight,
        'field_sku_option_id' => $option_id,
        'field_sku_attribute_id' => $attribute_id,
        'field_sku_attribute_code' => $attribute_code,
      ]);
      try {
        $term->save();
      }
      catch (EntityStorageException $exception) {
        $this->logger->critical('Product option "@option" wasn\'t saved. Try again later please.', ['@option' => $option_value]);
      }
    }

    return $term;
  }
protected function createProductOption($langcode, $option_id, $option_value, $attribute_id, $attribute_code, $weight) {
    if (strlen($option_value) == 0) {
      $this->logger->warning('Got empty value while syncing production options: @data', [
        '@data' => json_encode([
          'langcode' => $langcode,
          'option_id' => $option_id,
          'attribute_id' => $attribute_id,
          'attribute_code' => $attribute_code,
        ]),
      ]);

      return NULL;
    }

    // Update the term if already available.
    if ($term = $this->loadProductOptionByOptionId($attribute_code, $option_id, NULL, FALSE)) {
      $save_term = FALSE;

      // Save term even if weight changes.
      if ($term->getWeight() != $weight) {
        $save_term = TRUE;
      }

      if ($term->hasTranslation($langcode)) {
        $term = $term->getTranslation($langcode);

        // We won't allow editing name here, if required it must be done from
        // Magento.
        if ($term->getName() != $option_value) {
          $term->setName($option_value);
          $save_term = TRUE;
        }
      }
      else {
        $term = $term->addTranslation($langcode, []);
        $term->setName($option_value);
        $save_term = TRUE;
      }

      if ($save_term) {
        $term->setWeight($weight);
        $term->save();
      }
    }
    else {
      $term = $this->termStorage->create([
        'vid' => self::PRODUCT_OPTIONS_VOCABULARY,
        'langcode' => $langcode,
        'name' => $option_value,
        'weight' => $weight,
        'field_sku_option_id' => $option_id,
        'field_sku_attribute_id' => $attribute_id,
        'field_sku_attribute_code' => $attribute_code,
      ]);
      try {
        $term->save();
      }
      catch (EntityStorageException $exception) {
        $this->logger->critical('Product option "@option" wasn\'t saved. Try again later please.', ['@option' => $option_value]);
      }
    }

    return $term;
  }
protected function createProductOption ( $ langcode , $ option_id , $ option_value , $ attribute_id , $ attribute_code , $ weight ) { if ( strlen ( $ option_value ) == 0 ) { $ this -> logger -> warning ( 'Got empty value while syncing production options: @data' , [ '@data' => json_encode ( [ 'langcode' => $ langcode , 'option_id' => $ option_id , 'attribute_id' => $ attribute_id , 'attribute_code' => $ attribute_code , ] ) , ] ) ; return NULL ; } // Update the term if already available. if ( $ term = $ this -> loadProductOptionByOptionId ( $ attribute_code , $ option_id , NULL , FALSE ) ) { $ save_term = FALSE ; // Save term even if weight changes. if ( $ term -> getWeight ( ) != $ weight ) { $ save_term = TRUE ; } if ( $ term -> hasTranslation ( $ langcode ) ) { $ term = $ term -> getTranslation ( $ langcode ) ; // We won't allow editing name here, if required it must be done from // Magento. if ( $ term -> getName ( ) != $ option_value ) { $ term -> setName ( $ option_value ) ; $ save_term = TRUE ; } } else { $ term = $ term -> addTranslation ( $ langcode , [ ] ) ; $ term -> setName ( $ option_value ) ; $ save_term = TRUE ; } if ( $ save_term ) { $ term -> setWeight ( $ weight ) ; $ term -> save ( ) ; } } else { $ term = $ this -> termStorage -> create ( [ 'vid' => self :: PRODUCT_OPTIONS_VOCABULARY , 'langcode' => $ langcode , 'name' => $ option_value , 'weight' => $ weight , 'field_sku_option_id' => $ option_id , 'field_sku_attribute_id' => $ attribute_id , 'field_sku_attribute_code' => $ attribute_code , ] ) ; try { $ term -> save ( ) ; } catch ( EntityStorageException $ exception ) { $ this -> logger -> critical ( 'Product option "@option" wasn\'t saved. Try again later please.' , [ '@option' => $ option_value ] ) ; } } return $ term ; }
Create product option if not available or update the name.

@param string $langcode
Lang code.
@param int $option_id
Option id.
@param string $option_value
Value (term name).
@param int $attribute_id
Attribute id.
@param string $attribute_code
Attribute code.
@param int $weight
Taxonomy term weight == attribute option sort order.

@return \Drupal\taxonomy\Entity\Term|null
Term object or null.
Create product option if not available or update the name .