public function OrderTotalPrice::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/
order/ src/ Plugin/ Commerce/ Condition/ OrderTotalPrice.php, line 76
Class
- OrderTotalPrice
- Provides the total price condition for orders.
Namespace
Drupal\commerce_order\Plugin\Commerce\ConditionCode
public function evaluate(EntityInterface $entity) {
$this
->assertEntity($entity);
/** @var \Drupal\commerce_order\Entity\OrderInterface $order */
$order = $entity;
$total_price = $order
->getTotalPrice();
if (!$total_price) {
return FALSE;
}
$condition_price = Price::fromArray($this->configuration['amount']);
if ($total_price
->getCurrencyCode() != $condition_price
->getCurrencyCode()) {
return FALSE;
}
switch ($this->configuration['operator']) {
case '>=':
return $total_price
->greaterThanOrEqual($condition_price);
case '>':
return $total_price
->greaterThan($condition_price);
case '<=':
return $total_price
->lessThanOrEqual($condition_price);
case '<':
return $total_price
->lessThan($condition_price);
case '==':
return $total_price
->equals($condition_price);
default:
throw new \InvalidArgumentException("Invalid operator {$this->configuration['operator']}");
}
}