modules/acm_sku/src/StockManager.php
public function getStock(string $sku) {
    $query = $this->connection->select('acm_sku_stock');
    $query->fields('acm_sku_stock');
    $query->condition('sku', $sku);
    $result = $query->execute()->fetchAll();

    // We may not have any entry.
    if (empty($result)) {
      return [];
    }

    // Log if more than one found.
    if (count($result) > 1) {
      $this->logger->error('Duplicate entries found for stock of sku @sku.', [
        '@sku' => $sku,
      ]);
    }

    // Get the first result.
    $data = reset($result);

    return (array) $data;
  }
public function getStock(string $sku) {
    $query = $this->connection->select('acm_sku_stock');
    $query->fields('acm_sku_stock');
    $query->condition('sku', $sku);
    $result = $query->execute()->fetchAll();

    // We may not have any entry.
    if (empty($result)) {
      return [];
    }

    // Log if more than one found.
    if (count($result) > 1) {
      $this->logger->error('Duplicate entries found for stock of sku @sku.', [
        '@sku' => $sku,
      ]);
    }

    // Get the first result.
    $data = reset($result);

    return (array) $data;
  }
public function getStock ( string $ sku ) { $ query = $ this -> connection -> select ( 'acm_sku_stock' ) ; $ query -> fields ( 'acm_sku_stock' ) ; $ query -> condition ( 'sku' , $ sku ) ; $ result = $ query -> execute ( ) -> fetchAll ( ) ; // We may not have any entry. if ( empty ( $ result ) ) { return [ ] ; } // Log if more than one found. if ( count ( $ result ) > 1 ) { $ this -> logger -> error ( 'Duplicate entries found for stock of sku @sku.' , [ '@sku' => $ sku , ] ) ; } // Get the first result. $ data = reset ( $ result ) ; return ( array ) $ data ; }
Get current stock data for SKU from DB.

@param string $sku
SKU string.

@return array
Stock data with keys [sku, status, quantity].
Get current stock data for SKU from DB .