protected function BuyXGetY::findSinglePurchasableEntity in Commerce Core 8.2
Finds the configured purchasable entity amongst the given conditions.
Parameters
\Drupal\commerce\ConditionGroup $conditions: The condition group.
Return value
\Drupal\commerce\PurchasableEntityInterface|null The purchasable entity, or NULL if not found in the conditions.
1 call to BuyXGetY::findSinglePurchasableEntity()
- BuyXGetY::apply in modules/
promotion/ src/ Plugin/ Commerce/ PromotionOffer/ BuyXGetY.php - Applies the offer to the given entity.
File
- modules/
promotion/ src/ Plugin/ Commerce/ PromotionOffer/ BuyXGetY.php, line 548
Class
- BuyXGetY
- Provides the "Buy X Get Y" offer for orders.
Namespace
Drupal\commerce_promotion\Plugin\Commerce\PromotionOfferCode
protected function findSinglePurchasableEntity(ConditionGroup $conditions) {
foreach ($conditions
->getConditions() as $condition) {
if ($condition instanceof PurchasableEntityConditionInterface) {
$purchasable_entity_ids = $condition
->getPurchasableEntityIds();
if (count($purchasable_entity_ids) === 1) {
$purchasable_entities = $condition
->getPurchasableEntities();
return reset($purchasable_entities);
}
}
}
return NULL;
}