modules/acm_sku/src/ProductManager.php
public function updateNodeTranslation(NodeInterface &$node, array $product, string $langcode) {
    $description = (isset($product['attributes']['description'])) ? $product['attributes']['description'] : '';

    $categories = (isset($product['categories'])) ? $product['categories'] : [];

    $config = $this->configFactory->get('acm.connector');
    $sku_field_name = $config->get('sku_field_name') ?: 'field_skus';
    $category_field_name = $config->get('category_field_name');
    $text_format = $config->get('text_format') ?: 'rich_text';

    $node_title = html_entity_decode($product['name']);
    if ($config->get('product_title_use_sku')) {
      $node_title = html_entity_decode($product['sku']);
    }
    $node->setTitle($node_title);
    $body = [
      'value' => $description,
      'format' => $text_format,
    ];
    $node->set('body', $body);

    // Add categories if they're configured to be synced.
    if ($category_field_name) {
      $categories = $this->formatCategories($categories);
      $node->{$category_field_name} = $categories;
    }
    $node->{$sku_field_name} = [$product['sku']];

    if ($config->get('product_publish')) {
      $node->setPublished();
    }
    else {
      $node->setUnpublished();
    }

    // Invoke the alter hook to allow all modules to update the node.
    $this->moduleHandler->alter('acm_sku_product_node_translation_update', $node, $product, $langcode);
  }
public function updateNodeTranslation(NodeInterface &$node, array $product, string $langcode) {
    $description = (isset($product['attributes']['description'])) ? $product['attributes']['description'] : '';

    $categories = (isset($product['categories'])) ? $product['categories'] : [];

    $config = $this->configFactory->get('acm.connector');
    $sku_field_name = $config->get('sku_field_name') ?: 'field_skus';
    $category_field_name = $config->get('category_field_name');
    $text_format = $config->get('text_format') ?: 'rich_text';

    $node_title = html_entity_decode($product['name']);
    if ($config->get('product_title_use_sku')) {
      $node_title = html_entity_decode($product['sku']);
    }
    $node->setTitle($node_title);
    $body = [
      'value' => $description,
      'format' => $text_format,
    ];
    $node->set('body', $body);

    // Add categories if they're configured to be synced.
    if ($category_field_name) {
      $categories = $this->formatCategories($categories);
      $node->{$category_field_name} = $categories;
    }
    $node->{$sku_field_name} = [$product['sku']];

    if ($config->get('product_publish')) {
      $node->setPublished();
    }
    else {
      $node->setUnpublished();
    }

    // Invoke the alter hook to allow all modules to update the node.
    $this->moduleHandler->alter('acm_sku_product_node_translation_update', $node, $product, $langcode);
  }
public function updateNodeTranslation ( NodeInterface & $ node , array $ product , string $ langcode ) { $ description = ( isset ( $ product [ 'attributes' ] [ 'description' ] ) ) ? $ product [ 'attributes' ] [ 'description' ] : '' ; $ categories = ( isset ( $ product [ 'categories' ] ) ) ? $ product [ 'categories' ] : [ ] ; $ config = $ this -> configFactory -> get ( 'acm.connector' ) ; $ sku_field_name = $ config -> get ( 'sku_field_name' ) ? : 'field_skus' ; $ category_field_name = $ config -> get ( 'category_field_name' ) ; $ text_format = $ config -> get ( 'text_format' ) ? : 'rich_text' ; $ node_title = html_entity_decode ( $ product [ 'name' ] ) ; if ( $ config -> get ( 'product_title_use_sku' ) ) { $ node_title = html_entity_decode ( $ product [ 'sku' ] ) ; } $ node -> setTitle ( $ node_title ) ; $ body = [ 'value' => $ description , 'format' => $ text_format , ] ; $ node -> set ( 'body' , $ body ) ; // Add categories if they're configured to be synced. if ( $ category_field_name ) { $ categories = $ this -> formatCategories ( $ categories ) ; $ node -> { $ category_field_name } = $ categories ; } $ node -> { $ sku_field_name } = [ $ product [ 'sku' ] ] ; if ( $ config -> get ( 'product_publish' ) ) { $ node -> setPublished ( ) ; } else { $ node -> setUnpublished ( ) ; } // Invoke the alter hook to allow all modules to update the node. $ this -> moduleHandler -> alter ( 'acm_sku_product_node_translation_update' , $ node , $ product , $ langcode ) ; }
Update node translation.

@param \Drupal\node\NodeInterface $node
Object of node we want to update with precreated translation.
@param array $product
Array with product values.
@param string $langcode
Langcode string.
Update node translation .