You are here

public function OrderBillingAddress::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/OrderBillingAddress.php, line 67

Class

OrderBillingAddress
Provides the billing address condition for orders.

Namespace

Drupal\commerce_order\Plugin\Commerce\Condition

Code

public function evaluate(EntityInterface $entity) {
  $this
    ->assertEntity($entity);

  /** @var \Drupal\commerce_order\Entity\OrderInterface $order */
  $order = $entity;
  $billing_profile = $order
    ->getBillingProfile();
  if (!$billing_profile) {

    // The promotion can't be applied until the billing address is known.
    return FALSE;
  }
  $zone = new Zone([
    'id' => 'billing',
    'label' => 'N/A',
  ] + $this->configuration['zone']);
  $address = $billing_profile
    ->get('address')
    ->first();
  return $zone
    ->match($address);
}