You are here

trait StockTransactionQueryTrait in Commerce Stock 8

Provides methods to query the transaction database.

Hierarchy

3 files declare their use of StockTransactionQueryTrait
StockLevelTest.php in modules/field/tests/src/Kernel/StockLevelTest.php
StockLevelWidgetsTest.php in modules/ui/tests/Functional/StockLevelWidgetsTest.php
StockLevelWidgetsTest.php in modules/field/tests/src/Functional/StockLevelWidgetsTest.php

File

modules/local_storage/tests/src/Kernel/StockTransactionQueryTrait.php, line 8

Namespace

Drupal\Tests\commerce_stock_local\Kernel
View source
trait StockTransactionQueryTrait {

  /**
   * Return the last transaction for a entity.
   *
   * @param string $entity_id
   *   The id of the entity to.
   *
   * @return obj
   *   The transaction.
   */
  protected function getLastEntityTransaction($entity_id) {
    $connection = \Drupal::database();
    $query = $connection
      ->select('commerce_stock_transaction', 'txn')
      ->fields('txn')
      ->condition('entity_id', $entity_id)
      ->orderBy('id', 'DESC')
      ->range(0, 1);
    return $query
      ->execute()
      ->fetchObject();
  }

  /**
   * Return the last transaction in the table.
   *
   * @return obj
   *   The transaction.
   */
  protected function getLastTransaction() {
    $connection = \Drupal::database();
    $query = $connection
      ->select('commerce_stock_transaction', 'txn')
      ->fields('txn')
      ->orderBy('id', 'DESC')
      ->range(0, 1);
    return $query
      ->execute()
      ->fetchObject();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
StockTransactionQueryTrait::getLastEntityTransaction protected function Return the last transaction for a entity.
StockTransactionQueryTrait::getLastTransaction protected function Return the last transaction in the table.