You are here

public function XquantityStockAvailabilityChecker::applies in Commerce Extended Quantity 8

Determines whether the checker applies to the given purchasable entity.

Parameters

\Drupal\commerce_order\Entity\OrderItemInterface $order_item: The order item.

Return value

bool TRUE if the checker applies to the given purchasable entity, FALSE otherwise.

Overrides AvailabilityCheckerInterface::applies

File

modules/xquantity_stock/src/XquantityStockAvailabilityChecker.php, line 23

Class

XquantityStockAvailabilityChecker

Namespace

Drupal\xquantity_stock

Code

public function applies(OrderItemInterface $order_item) {
  $entity = $order_item
    ->getPurchasedEntity();
  $applies = FALSE;
  foreach (array_reverse($entity
    ->getFieldDefinitions()) as $definition) {
    if ($definition
      ->getType() == 'xquantity_stock') {
      $applies = TRUE;
      break;
    }
  }

  // Allow modules to apply their own logic.
  \Drupal::moduleHandler()
    ->alter("xquantity_availability_applies", $applies, $entity);
  return $applies;
}