modules/acm_sku/src/AcquiaCommerce/SKUPluginBase.php
public function getParentSku(SKU $sku) {
    $static = &drupal_static(__FUNCTION__, []);

    $langcode = $sku->language()->getId();
    $sku_string = $sku->getSku();

    if (isset($static[$langcode], $static[$langcode][$sku_string])) {
      return $static[$langcode][$sku_string];
    }

    // Initialise with empty value.
    $static[$langcode][$sku_string] = NULL;

    $parent_skus = array_keys($this->getAllParentSkus($sku_string));

    if (empty($parent_skus)) {
      return NULL;
    }

    if (count($parent_skus) > 1) {
      \Drupal::logger('acm_sku')->warning(
        'Multiple parents found for SKU: @sku, parents: @parents',
        [
          '@parents' => implode(',', $parent_skus),
          '@sku' => $sku_string,
        ]
      );
    }

    foreach ($parent_skus as $parent_sku) {
      $parent = SKU::loadFromSku($parent_sku, $langcode);
      if ($parent instanceof SKU) {
        $node = $this->getDisplayNode($parent, FALSE, FALSE);

        if ($node instanceof Node) {
          $static[$langcode][$sku_string] = $parent;
          break;
        }
      }
    }

    return $static[$langcode][$sku_string];
  }
public function getParentSku(SKU $sku) {
    $static = &drupal_static(__FUNCTION__, []);

    $langcode = $sku->language()->getId();
    $sku_string = $sku->getSku();

    if (isset($static[$langcode], $static[$langcode][$sku_string])) {
      return $static[$langcode][$sku_string];
    }

    // Initialise with empty value.
    $static[$langcode][$sku_string] = NULL;

    $parent_skus = array_keys($this->getAllParentSkus($sku_string));

    if (empty($parent_skus)) {
      return NULL;
    }

    if (count($parent_skus) > 1) {
      \Drupal::logger('acm_sku')->warning(
        'Multiple parents found for SKU: @sku, parents: @parents',
        [
          '@parents' => implode(',', $parent_skus),
          '@sku' => $sku_string,
        ]
      );
    }

    foreach ($parent_skus as $parent_sku) {
      $parent = SKU::loadFromSku($parent_sku, $langcode);
      if ($parent instanceof SKU) {
        $node = $this->getDisplayNode($parent, FALSE, FALSE);

        if ($node instanceof Node) {
          $static[$langcode][$sku_string] = $parent;
          break;
        }
      }
    }

    return $static[$langcode][$sku_string];
  }
public function getParentSku ( SKU $ sku ) { $ static = & drupal_static ( __FUNCTION__ , [ ] ) ; $ langcode = $ sku -> language ( ) -> getId ( ) ; $ sku_string = $ sku -> getSku ( ) ; if ( isset ( $ static [ $ langcode ] , $ static [ $ langcode ] [ $ sku_string ] ) ) { return $ static [ $ langcode ] [ $ sku_string ] ; } // Initialise with empty value. $ static [ $ langcode ] [ $ sku_string ] = NULL ; $ parent_skus = array_keys ( $ this -> getAllParentSkus ( $ sku_string ) ) ; if ( empty ( $ parent_skus ) ) { return NULL ; } if ( count ( $ parent_skus ) > 1 ) { \ Drupal :: logger ( 'acm_sku' ) -> warning ( 'Multiple parents found for SKU: @sku, parents: @parents' , [ '@parents' => implode ( ',' , $ parent_skus ) , '@sku' => $ sku_string , ] ) ; } foreach ( $ parent_skus as $ parent_sku ) { $ parent = SKU :: loadFromSku ( $ parent_sku , $ langcode ) ; if ( $ parent instanceof SKU ) { $ node = $ this -> getDisplayNode ( $ parent , FALSE , FALSE ) ; if ( $ node instanceof Node ) { $ static [ $ langcode ] [ $ sku_string ] = $ parent ; break ; } } } return $ static [ $ langcode ] [ $ sku_string ] ; }
Get parent of current product.

@param \Drupal\acm_sku\Entity\SKU $sku
Current product.

@return \Drupal\acm_sku\Entity\SKU|null
Parent product or null if not found.

@throws \Exception
Get parent of current product .