modules/acm_sku/src/StockManager.php
public function isProductInStock(SKU $sku) {
    $sku_string = $sku->getSku();

    $static = &drupal_static(self::class . '_' . __FUNCTION__, []);
    if (isset($static[$sku_string])) {
      return $static[$sku_string];
    }

    // Initialise static value with FALSE.
    $static[$sku_string] = FALSE;

    $stock = $this->getStock($sku_string);
    if (empty($stock['status'])) {
      return FALSE;
    }

    // Check status + quantity of children if configurable.
    switch ($sku->bundle()) {
      case 'configurable':
        // For configurable product to be in-stock only one in-stock child
        // is enough.
        foreach ($sku->get('field_configured_skus')->getValue() as $child) {
          if (empty($child['value'])) {
            continue;
          }

          $child_sku = SKU::loadFromSku($child['value']);
          if ($child_sku instanceof SKU) {
            if ($this->getStockQuantity($child_sku->getSku()) > 0) {
              $static[$sku_string] = TRUE;
              break;
            }
          }
        }
        break;

      case 'simple':
      default:
        $static[$sku_string] = (bool) $this->getStockQuantity($sku->getSku());
        break;
    }

    return $static[$sku_string];
  }
public function isProductInStock(SKU $sku) {
    $sku_string = $sku->getSku();

    $static = &drupal_static(self::class . '_' . __FUNCTION__, []);
    if (isset($static[$sku_string])) {
      return $static[$sku_string];
    }

    // Initialise static value with FALSE.
    $static[$sku_string] = FALSE;

    $stock = $this->getStock($sku_string);
    if (empty($stock['status'])) {
      return FALSE;
    }

    // Check status + quantity of children if configurable.
    switch ($sku->bundle()) {
      case 'configurable':
        // For configurable product to be in-stock only one in-stock child
        // is enough.
        foreach ($sku->get('field_configured_skus')->getValue() as $child) {
          if (empty($child['value'])) {
            continue;
          }

          $child_sku = SKU::loadFromSku($child['value']);
          if ($child_sku instanceof SKU) {
            if ($this->getStockQuantity($child_sku->getSku()) > 0) {
              $static[$sku_string] = TRUE;
              break;
            }
          }
        }
        break;

      case 'simple':
      default:
        $static[$sku_string] = (bool) $this->getStockQuantity($sku->getSku());
        break;
    }

    return $static[$sku_string];
  }
public function isProductInStock ( SKU $ sku ) { $ sku_string = $ sku -> getSku ( ) ; $ static = & drupal_static ( self :: class . '_' . __FUNCTION__ , [ ] ) ; if ( isset ( $ static [ $ sku_string ] ) ) { return $ static [ $ sku_string ] ; } // Initialise static value with FALSE. $ static [ $ sku_string ] = FALSE ; $ stock = $ this -> getStock ( $ sku_string ) ; if ( empty ( $ stock [ 'status' ] ) ) { return FALSE ; } // Check status + quantity of children if configurable. switch ( $ sku -> bundle ( ) ) { case 'configurable' : // For configurable product to be in-stock only one in-stock child // is enough. foreach ( $ sku -> get ( 'field_configured_skus' ) -> getValue ( ) as $ child ) { if ( empty ( $ child [ 'value' ] ) ) { continue ; } $ child_sku = SKU :: loadFromSku ( $ child [ 'value' ] ) ; if ( $ child_sku instanceof SKU ) { if ( $ this -> getStockQuantity ( $ child_sku -> getSku ( ) ) > 0 ) { $ static [ $ sku_string ] = TRUE ; break ; } } } break ; case 'simple' : default : $ static [ $ sku_string ] = ( bool ) $ this -> getStockQuantity ( $ sku -> getSku ( ) ) ; break ; } return $ static [ $ sku_string ] ; }
Check if product is in stock.

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

@return bool
TRUE if product is in stock.
Check if product is in stock .