public function StockLocationStorage::loadEnabled in Commerce Stock 8
Loads the enabled locations for the given Purchasable Entity.
Enabled variations are active stock locations that have been filtered through the FILTER_STOCK_LOCATIONS event.
Parameters
\Drupal\commerce\PurchasableEntityInterface $entity: The purchasable entity.
Return value
\Drupal\commerce_stock_local\Entity\StockLocation[] The enabled stock locations.
Overrides StockLocationStorageInterface::loadEnabled
1 call to StockLocationStorage::loadEnabled()
- StockLocationStorage::loadInContext in modules/
local_storage/ src/ StockLocationStorage.php - Loads the relevant locations for the given Purchasable Entity and context.
File
- modules/
local_storage/ src/ StockLocationStorage.php, line 19
Class
- StockLocationStorage
- Defines the local stock location storage.
Namespace
Drupal\commerce_stock_localCode
public function loadEnabled(PurchasableEntityInterface $entity) {
// Speed up loading by filtering out the IDs of disabled locations.
$query = $this
->getQuery()
->condition('status', TRUE);
$result = $query
->execute();
if (empty($result)) {
return [];
}
$enabled_locations = $this
->loadMultiple($result);
// Allow modules to apply own filtering.
$event = new FilterLocationsEvent($entity, $enabled_locations);
$this->eventDispatcher
->dispatch(LocalStockEvents::FILTER_STOCK_LOCATIONS, $event);
$enabled_locations = $event
->getLocations();
return $enabled_locations;
}