public function ShipmentAddress::evaluate in Commerce Shipping 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
- src/
Plugin/ Commerce/ Condition/ ShipmentAddress.php, line 77
Class
- ShipmentAddress
- Provides the shipping address condition for shipments.
Namespace
Drupal\commerce_shipping\Plugin\Commerce\ConditionCode
public function evaluate(EntityInterface $entity) {
$this
->assertEntity($entity);
/** @var \Drupal\commerce_shipping\Entity\ShipmentInterface $shipment */
$shipment = $entity;
$shipping_profile = $shipment
->getShippingProfile();
if (!$shipping_profile) {
return FALSE;
}
$address = $shipping_profile
->get('address')
->first();
if (!$address) {
// The conditions can't be applied until the shipping address is known.
return FALSE;
}
$zone = new Zone([
'id' => 'shipping',
'label' => 'N/A',
] + $this->configuration['zone']);
if ($this->configuration['negate']) {
return !$zone
->match($address);
}
return $zone
->match($address);
}