You are here

class CommerceLocalStockTransactionSubscriber in Commerce Stock 8

Test class to test the commerce_stock transaction events.

Hierarchy

Expanded class hierarchy of CommerceLocalStockTransactionSubscriber

1 string reference to 'CommerceLocalStockTransactionSubscriber'
commerce_stock_local.services.yml in modules/local_storage/commerce_stock_local.services.yml
modules/local_storage/commerce_stock_local.services.yml
1 service uses CommerceLocalStockTransactionSubscriber
commerce_stock_local.transaction_subscriber in modules/local_storage/commerce_stock_local.services.yml
Drupal\commerce_stock_local\EventSubscriber\CommerceLocalStockTransactionSubscriber

File

modules/local_storage/src/EventSubscriber/CommerceLocalStockTransactionSubscriber.php, line 13

Namespace

Drupal\commerce_stock_local\EventSubscriber
View source
class CommerceLocalStockTransactionSubscriber implements EventSubscriberInterface {

  /**
   * The cache tags invalidator.
   *
   * @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface
   */
  protected $cacheTagsInvalidator;

  /**
   * Constructs a CommerceStockTransactionSubscriber.
   *
   * @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $cache_tags_invalidator
   *   The cache tags invalidator.
   */
  public function __construct(CacheTagsInvalidatorInterface $cache_tags_invalidator) {
    $this->cacheTagsInvalidator = $cache_tags_invalidator;
  }

  /**
   * @inheritDoc
   */
  public static function getSubscribedEvents() {
    return [
      LocalStockTransactionEvents::LOCAL_STOCK_TRANSACTION_INSERT => 'onTransactionInsert',
    ];
  }

  /**
   * Invalidate the cache for the purchased entity.
   *
   * @param \Drupal\commerce_stock_local\Event\LocalStockTransactionEvent $event
   *   The event.
   */
  public function onTransactionInsert(LocalStockTransactionEvent $event) {
    $purchasableEntity = $event
      ->getEntity();
    $this->cacheTagsInvalidator
      ->invalidateTags($purchasableEntity
      ->getCacheTagsToInvalidate());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CommerceLocalStockTransactionSubscriber::$cacheTagsInvalidator protected property The cache tags invalidator.
CommerceLocalStockTransactionSubscriber::getSubscribedEvents public static function @inheritDoc
CommerceLocalStockTransactionSubscriber::onTransactionInsert public function Invalidate the cache for the purchased entity.
CommerceLocalStockTransactionSubscriber::__construct public function Constructs a CommerceStockTransactionSubscriber.