You are here

public function StockServiceManager::getService in Commerce Stock 8

Get a service relevant for the entity.

Parameters

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

Return value

\Drupal\commerce_stock\StockServiceInterface The appropriate stock service for the given purchasable entity.

Overrides StockServiceManagerInterface::getService

File

src/StockServiceManager.php, line 78

Class

StockServiceManager
The stock service manager.

Namespace

Drupal\commerce_stock

Code

public function getService(PurchasableEntityInterface $entity) {
  $config = $this->configFactory
    ->get('commerce_stock.service_manager');
  $default_service_id = $config
    ->get('default_service_id');
  $entity_type = $entity
    ->getEntityTypeId();
  $entity_bundle = $entity
    ->bundle();
  $entity_config_key = $entity_type . '_' . $entity_bundle . '_service_id';
  $entity_service_id = $config
    ->get($entity_config_key);
  $service_id = $entity_service_id ?: $default_service_id;
  return $this->stockServices[$service_id];
}