You are here

interface StockTransactionsInterface in Commerce Stock 8

Defines a common interface for creating stock transactions.

Hierarchy

Expanded class hierarchy of StockTransactionsInterface

All classes that implement StockTransactionsInterface

10 files declare their use of StockTransactionsInterface
EnforcementBrowserTest.php in modules/enforcement/tests/src/Functional/EnforcementBrowserTest.php
LocalStockUpdaterTest.php in modules/local_storage/tests/src/Kernel/LocalStockUpdaterTest.php
OrderEventsTransactionsTest.php in modules/local_storage/tests/src/Kernel/OrderEventsTransactionsTest.php
OrderEventSubscriber.php in src/EventSubscriber/OrderEventSubscriber.php
OrderEventTransactionsKernelTest.php in modules/local_storage/tests/src/Kernel/OrderEventTransactionsKernelTest.php

... See full list

File

src/StockTransactionsInterface.php, line 11

Namespace

Drupal\commerce_stock
View source
interface StockTransactionsInterface {
  const STOCK_IN = 1;
  const STOCK_OUT = 2;
  const STOCK_SALE = 4;
  const STOCK_RETURN = 5;
  const NEW_STOCK = 6;
  const MOVEMENT_FROM = 7;
  const MOVEMENT_TO = 8;

  /**
   * Returns the active commerce context.
   *
   * This is to support UI calls.
   *
   * @param \Drupal\commerce\PurchasableEntityInterface $entity
   *   The purchasable entity (most likely a product variation entity).
   *
   * @throws \Exception
   *
   * @return \Drupal\commerce\Context
   *   The context containing the customer & store.
   */
  public function getContext(PurchasableEntityInterface $entity);

  /**
   * Checks that the context returned is valid for $entity.
   *
   * This is to support UI calls.
   *
   * @param \Drupal\commerce\PurchasableEntityInterface $entity
   *   The purchasable entity (most likely a product variation entity).
   *
   * @return bool
   *   TRUE if valid, FALSE if not.
   */
  public function isValidContext(PurchasableEntityInterface $entity);

  /**
   * Get the location to be used for automatic stock allocation.
   *
   * This is normally done by calling the stock service
   * StockServiceConfigInterface getTransactionLocation() and is provided as a
   * util function.
   *
   * @param \Drupal\commerce\Context $context
   *   The context containing the customer & store.
   * @param \Drupal\commerce\PurchasableEntityInterface $entity
   *   The purchasable entity (most likely a product variation entity).
   * @param int $quantity
   *   The quantity.
   *
   * @return \Drupal\commerce_stock\StockLocationInterface
   *   The stock location.
   */
  public function getTransactionLocation(Context $context, PurchasableEntityInterface $entity, $quantity);

  /**
   * Create a transaction.
   *
   * @param \Drupal\commerce\PurchasableEntityInterface $entity
   *   The purchasable entity (most likely a product variation entity).
   * @param int $location_id
   *   The location ID.
   * @param string $zone
   *   The zone.
   * @param float $quantity
   *   The quantity.
   * @param float $unit_cost
   *   The unit cost.
   * @param string $currency_code
   *   The currency code.
   * @param int $transaction_type_id
   *   Transaction type ID.
   * @param array $metadata
   *   A metadata array.
   */
  public function createTransaction(PurchasableEntityInterface $entity, $location_id, $zone, $quantity, $unit_cost, $currency_code, $transaction_type_id, array $metadata = []);

  /**
   * Receive stock.
   *
   * @param \Drupal\commerce\PurchasableEntityInterface $entity
   *   The purchasable entity (most likely a product variation entity).
   * @param int $location_id
   *   The location ID.
   * @param string $zone
   *   The zone.
   * @param float $quantity
   *   The quantity.
   * @param float $unit_cost
   *   The unit cost.
   * @param string $currency_code
   *   The currency code.
   * @param string $message
   *   The message.
   */
  public function receiveStock(PurchasableEntityInterface $entity, $location_id, $zone, $quantity, $unit_cost, $currency_code, $message = NULL);

  /**
   * Sell stock.
   *
   * @param \Drupal\commerce\PurchasableEntityInterface $entity
   *   The purchasable entity (most likely a product variation entity).
   * @param int $location_id
   *   The location ID.
   * @param string $zone
   *   The zone.
   * @param float $quantity
   *   The quantity.
   * @param float $unit_cost
   *   The unit cost.
   * @param string $currency_code
   *   The currency code.
   * @param int $order_id
   *   The order ID.
   * @param int $user_id
   *   The user ID.
   * @param string $message
   *   The message.
   */
  public function sellStock(PurchasableEntityInterface $entity, $location_id, $zone, $quantity, $unit_cost, $currency_code, $order_id, $user_id, $message = NULL);

  /**
   * Move stock.
   *
   * @param \Drupal\commerce\PurchasableEntityInterface $entity
   *   The purchasable entity (most likely a product variation entity).
   * @param int $from_location_id
   *   The source location ID.
   * @param int $to_location_id
   *   The target location ID.
   * @param string $from_zone
   *   The source zone.
   * @param string $to_zone
   *   The target zone.
   * @param float $quantity
   *   The quantity.
   * @param float $unit_cost
   *   The unit cost.
   * @param string $currency_code
   *   The currency code.
   * @param string $message
   *   The message.
   */
  public function moveStock(PurchasableEntityInterface $entity, $from_location_id, $to_location_id, $from_zone, $to_zone, $quantity, $unit_cost, $currency_code, $message = NULL);

  /**
   * Stock returns.
   *
   * @param \Drupal\commerce\PurchasableEntityInterface $entity
   *   The purchasable entity (most likely a product variation entity).
   * @param int $location_id
   *   The location ID.
   * @param string $zone
   *   The zone.
   * @param float $quantity
   *   The quantity.
   * @param float $unit_cost
   *   The unit cost.
   * @param string $currency_code
   *   The currency code.
   * @param int $order_id
   *   The order ID.
   * @param int $user_id
   *   The user ID.
   * @param string $message
   *   The message.
   */
  public function returnStock(PurchasableEntityInterface $entity, $location_id, $zone, $quantity, $unit_cost, $currency_code, $order_id, $user_id, $message = NULL);

}

Members

Namesort descending Modifiers Type Description Overrides
StockTransactionsInterface::createTransaction public function Create a transaction. 1
StockTransactionsInterface::getContext public function Returns the active commerce context.
StockTransactionsInterface::getTransactionLocation public function Get the location to be used for automatic stock allocation. 1
StockTransactionsInterface::isValidContext public function Checks that the context returned is valid for $entity.
StockTransactionsInterface::MOVEMENT_FROM constant
StockTransactionsInterface::MOVEMENT_TO constant
StockTransactionsInterface::moveStock public function Move stock. 1
StockTransactionsInterface::NEW_STOCK constant
StockTransactionsInterface::receiveStock public function Receive stock. 1
StockTransactionsInterface::returnStock public function Stock returns. 1
StockTransactionsInterface::sellStock public function Sell stock. 1
StockTransactionsInterface::STOCK_IN constant
StockTransactionsInterface::STOCK_OUT constant
StockTransactionsInterface::STOCK_RETURN constant
StockTransactionsInterface::STOCK_SALE constant