public function PriceListRepository::loadItem in Commerce Pricelist 8.2
Loads the price list item for the given purchasable entity.
Parameters
\Drupal\commerce\PurchasableEntityInterface $entity: The purchasable entity.
int $quantity: The quantity.
\Drupal\commerce\Context $context: The context.
Return value
\Drupal\commerce_pricelist\Entity\PriceListItemInterface|null The price list item, NULL if no matching price list item could be found.
Overrides PriceListRepositoryInterface::loadItem
File
- src/
PriceListRepository.php, line 47
Class
Namespace
Drupal\commerce_pricelistCode
public function loadItem(PurchasableEntityInterface $entity, $quantity, Context $context) {
$price_list_items = $this
->loadItems($entity, $context);
if (empty($price_list_items)) {
return NULL;
}
/** @var \Drupal\commerce_pricelist\Entity\PriceListItemInterface[] $price_list_items */
$price_list_items = array_filter($price_list_items, function ($price_list_item) use ($quantity) {
return $price_list_item
->getQuantity() <= $quantity;
});
$price_list_ids = $this
->loadPriceListIds($entity
->getEntityTypeId(), $context);
$price_list_item = $this
->selectPriceListItem($price_list_items, $price_list_ids);
return $price_list_item;
}