You are here

class AvailabilityManager in Commerce Core 8.2

Same name in this branch
  1. 8.2 src/AvailabilityManager.php \Drupal\commerce\AvailabilityManager
  2. 8.2 modules/order/src/AvailabilityManager.php \Drupal\commerce_order\AvailabilityManager

Default implementation of the availability manager.

Hierarchy

Expanded class hierarchy of AvailabilityManager

Deprecated

in commerce:8.x-2.18 and is removed from commerce:3.x. Use \Drupal\commerce_order\AvailabilityManager instead.

1 file declares its use of AvailabilityManager
AvailabilityManagerTest.php in tests/src/Unit/AvailabilityManagerTest.php
1 string reference to 'AvailabilityManager'
commerce.services.yml in ./commerce.services.yml
commerce.services.yml
1 service uses AvailabilityManager
commerce.availability_manager in ./commerce.services.yml
Drupal\commerce\AvailabilityManager

File

src/AvailabilityManager.php, line 11

Namespace

Drupal\commerce
View source
class AvailabilityManager implements AvailabilityManagerInterface {

  /**
   * The checkers.
   *
   * @var \Drupal\commerce\AvailabilityCheckerInterface[]
   */
  protected $checkers = [];

  /**
   * {@inheritdoc}
   */
  public function addChecker(AvailabilityCheckerInterface $checker) {
    $this->checkers[] = $checker;
  }

  /**
   * {@inheritdoc}
   */
  public function getCheckers() {
    return $this->checkers;
  }

  /**
   * {@inheritdoc}
   */
  public function check(PurchasableEntityInterface $entity, $quantity, Context $context) {
    @trigger_error('The ' . get_class($this) . ' is deprecated in commerce:8.x-2.18 and is removed from commerce:3.x. Use \\Drupal\\commerce_order\\AvailabilityManager instead.', E_USER_DEPRECATED);
    foreach ($this->checkers as $checker) {
      if ($checker
        ->applies($entity)) {
        $result = $checker
          ->check($entity, $quantity, $context);
        if ($result === FALSE) {
          return FALSE;
        }
      }
    }
    return TRUE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AvailabilityManager::$checkers protected property The checkers.
AvailabilityManager::addChecker public function Adds a checker. Overrides AvailabilityManagerInterface::addChecker
AvailabilityManager::check public function Checks the availability of the given purchasable entity. Overrides AvailabilityManagerInterface::check
AvailabilityManager::getCheckers public function Gets all added checkers. Overrides AvailabilityManagerInterface::getCheckers