You are here

private function OrderEventSubscriber::runTransactionEvent in Commerce Stock 8

Run the transaction event.

Parameters

\Drupal\commerce_stock\Plugin\Commerce\StockEventType\StockEventTypeInterface $event_type: The stock event type.

\Drupal\commerce\Context $context: The context containing the customer & store.

\Drupal\commerce\PurchasableEntityInterface $entity: The purchasable entity.

int $quantity: The quantity.

\Drupal\commerce_stock\StockLocationInterface $location: The stock location.

int $transaction_type_id: The transaction type ID.

\Drupal\commerce_order\Entity\Order $order: The original order the transaction belongs to.

Return value

int Return the ID of the transaction or FALSE if no transaction created.

6 calls to OrderEventSubscriber::runTransactionEvent()
OrderEventSubscriber::onOrderCancel in src/EventSubscriber/OrderEventSubscriber.php
Performs a stock transaction for an order Cancel event.
OrderEventSubscriber::onOrderDelete in src/EventSubscriber/OrderEventSubscriber.php
Performs a stock transaction on an order delete event.
OrderEventSubscriber::onOrderItemDelete in src/EventSubscriber/OrderEventSubscriber.php
Performs a stock transaction when an order item is deleted.
OrderEventSubscriber::onOrderItemUpdate in src/EventSubscriber/OrderEventSubscriber.php
Performs a stock transaction on an order item update.
OrderEventSubscriber::onOrderPlace in src/EventSubscriber/OrderEventSubscriber.php
Creates a stock transaction when an order is placed.

... See full list

File

src/EventSubscriber/OrderEventSubscriber.php, line 346

Class

OrderEventSubscriber
Performs stock transactions on order and order item events.

Namespace

Drupal\commerce_stock\EventSubscriber

Code

private function runTransactionEvent(StockEventTypeInterface $event_type, Context $context, PurchasableEntityInterface $entity, $quantity, StockLocationInterface $location, $transaction_type_id, Order $order) {
  $data['message'] = $event_type
    ->getDefaultMessage();
  $metadata = [
    'related_oid' => $order
      ->id(),
    'related_uid' => $order
      ->getCustomerId(),
    'data' => $data,
  ];
  $event_type_id = CoreStockEvents::mapStockEventIds($event_type
    ->getPluginId());
  return $this->eventsManager
    ->createInstance('core_stock_events')
    ->stockEvent($context, $entity, $event_type_id, $quantity, $location, $transaction_type_id, $metadata);
}