modules/acm_sku/src/ProductManager.php
private function updateLinkedSkus($type, SKU &$sku, array $linked) {
    // Reset the upsell skus to null.
    $sku->{$type}->setValue([]);
    $fieldData = [];
    foreach ($linked as $link) {
      if ($link['type'] != $type) {
        continue;
      }
      $fieldData[$link['position']] = $link['linked_sku'];
    }
    // If there is no upsell skus to link, we simply return from here.
    if (empty($fieldData)) {
      return;
    }
    // Sort them based on position.
    ksort($fieldData);
    // Update the index to sequential values so we can set in field.
    $fieldData = array_values($fieldData);
    foreach ($fieldData as $delta => $value) {
      $sku->{$type}->set($delta, $value);
    }
  }
private function updateLinkedSkus($type, SKU &$sku, array $linked) {
    // Reset the upsell skus to null.
    $sku->{$type}->setValue([]);
    $fieldData = [];
    foreach ($linked as $link) {
      if ($link['type'] != $type) {
        continue;
      }
      $fieldData[$link['position']] = $link['linked_sku'];
    }
    // If there is no upsell skus to link, we simply return from here.
    if (empty($fieldData)) {
      return;
    }
    // Sort them based on position.
    ksort($fieldData);
    // Update the index to sequential values so we can set in field.
    $fieldData = array_values($fieldData);
    foreach ($fieldData as $delta => $value) {
      $sku->{$type}->set($delta, $value);
    }
  }
private function updateLinkedSkus ( $ type , SKU & $ sku , array $ linked ) { // Reset the upsell skus to null. $ sku -> { $ type } -> setValue ( [ ] ) ; $ fieldData = [ ] ; foreach ( $ linked as $ link ) { if ( $ link [ 'type' ] != $ type ) { continue ; } $ fieldData [ $ link [ 'position' ] ] = $ link [ 'linked_sku' ] ; } // If there is no upsell skus to link, we simply return from here. if ( empty ( $ fieldData ) ) { return ; } // Sort them based on position. ksort ( $ fieldData ) ; // Update the index to sequential values so we can set in field. $ fieldData = array_values ( $ fieldData ) ; foreach ( $ fieldData as $ delta => $ value ) { $ sku -> { $ type } -> set ( $ delta , $ value ) ; } }
Update linked Skus.

Prepare the field value for linked type (upsell, crosssell, etc.).
Get the position based on the position coming from API.

@param string $type
Type of link.
@param \Drupal\acm_sku\Entity\SKU $sku
Root SKU.
@param array $linked
Linked SKUs.

@throws \Drupal\Core\TypedData\Exception\ReadOnlyException
If the data is read-only.
@throws \Drupal\Core\TypedData\Exception\MissingDataException
If the complex data structure is unset and no item can be set.
Update linked Skus .