public function OrderProductCategory::evaluate in Commerce Core 8.2
Evaluates the condition.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity.
Return value
bool TRUE if the condition has been met, FALSE otherwise.
Overrides ConditionInterface::evaluate
File
- modules/
product/ src/ Plugin/ Commerce/ Condition/ OrderProductCategory.php, line 70
Class
- OrderProductCategory
- Provides the product category condition for orders.
Namespace
Drupal\commerce_product\Plugin\Commerce\ConditionCode
public function evaluate(EntityInterface $entity) {
$this
->assertEntity($entity);
/** @var \Drupal\commerce_order\Entity\OrderInterface $order */
$order = $entity;
$term_ids = $this
->getTermIds();
foreach ($order
->getItems() as $order_item) {
/** @var \Drupal\commerce_product\Entity\ProductVariationInterface $purchased_entity */
$purchased_entity = $order_item
->getPurchasedEntity();
if (!$purchased_entity || $purchased_entity
->getEntityTypeId() != 'commerce_product_variation') {
continue;
}
$referenced_ids = $this
->getReferencedIds($purchased_entity
->getProduct());
if (array_intersect($term_ids, $referenced_ids)) {
return TRUE;
}
}
return FALSE;
}