You are here

public function ContextCreatorTrait::getContext in Commerce Stock 8

Returns the active commerce context.

This is to support UI calls.

Parameters

\Drupal\commerce\PurchasableEntityInterface $entity: The purchasable entity (most likely a product variation entity).

Return value

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

Throws

\Exception

3 calls to ContextCreatorTrait::getContext()
SimpleStockLevelWidget::formElement in modules/field/src/Plugin/Field/FieldWidget/SimpleStockLevelWidget.php
Returns the form for a single field widget.
StockLevel::createTransaction in modules/field/src/Plugin/Field/FieldType/StockLevel.php
Internal method to create transactions.
StockServiceManager::getStockLevel in src/StockServiceManager.php
Gets the total stock level for a given purchasable entity.

File

src/ContextCreatorTrait.php, line 27

Class

ContextCreatorTrait
Provides trait to create a commerce context object from a purchasable entity.

Namespace

Drupal\commerce_stock

Code

public function getContext(PurchasableEntityInterface $entity) {
  return $this
    ->getContextDetails($entity);
}