You are here

protected function ShipmentPromotionOfferBase::appliesToShipment in Commerce Shipping 8.2

Checks whether the promotion can be applied to the given shipment.

Parameters

\Drupal\commerce_shipping\Entity\ShipmentInterface $shipment: The shipment.

Return value

bool TRUE if promotion can be applied, FALSE otherwise.

1 call to ShipmentPromotionOfferBase::appliesToShipment()
ShipmentPromotionOfferBase::apply in src/Plugin/Commerce/PromotionOffer/ShipmentPromotionOfferBase.php
Applies the offer to the given entity.

File

src/Plugin/Commerce/PromotionOffer/ShipmentPromotionOfferBase.php, line 205

Class

ShipmentPromotionOfferBase
Provides the base class for shipment offers.

Namespace

Drupal\commerce_shipping\Plugin\Commerce\PromotionOffer

Code

protected function appliesToShipment(ShipmentInterface $shipment) {
  if (!$shipment
    ->getShippingMethodId() || !$shipment
    ->getAmount()) {

    // The shipment is still incomplete, skip it.
    return FALSE;
  }
  if ($this->configuration['filter'] == 'none') {

    // No filtering required.
    return TRUE;
  }
  $shipping_method = $shipment
    ->getShippingMethod();
  if (!$shipping_method) {

    // The referenced shipping method has been deleted.
    return FALSE;
  }
  $match = in_array($shipping_method
    ->uuid(), $this
    ->getShippingMethodUuids());
  return $this->configuration['filter'] == 'include' ? $match : !$match;
}