protected function PromotionSubscriber::getPromotions in Commerce Shipping 8.2
Gets the display-inclusive shipping promotions for the given order.
This includes both automatic and coupon-based promotions.
Parameters
\Drupal\commerce_order\Entity\OrderInterface $order: The order.
Return value
\Drupal\commerce_promotion\Entity\PromotionInterface[] The promotions.
1 call to PromotionSubscriber::getPromotions()
- PromotionSubscriber::onCalculate in src/
EventSubscriber/ PromotionSubscriber.php - Applies the promotions.
File
- src/
EventSubscriber/ PromotionSubscriber.php, line 108
Class
- PromotionSubscriber
- Applies display-inclusive promotions to the calculated shipping rates.
Namespace
Drupal\commerce_shipping\EventSubscriberCode
protected function getPromotions(OrderInterface $order) {
$offer_ids = $this
->getOfferIds();
if (!$offer_ids) {
return [];
}
$promotions = $this->promotionStorage
->loadAvailable($order, $offer_ids);
$coupons = $this
->getCoupons($order, $offer_ids);
foreach ($coupons as $coupon) {
$promotion = $coupon
->getPromotion();
$promotions[$promotion
->id()] = $promotion;
}
$promotions = array_filter($promotions, function (PromotionInterface $promotion) {
$offer = $promotion
->getOffer();
// If this is a combination offer, check if there is a display inclusive
// shipment promotion offer configured.
if ($offer instanceof CombinationOfferInterface) {
foreach ($offer
->getOffers() as $configured_offer) {
if (!$configured_offer instanceof ShipmentPromotionOfferInterface) {
continue;
}
if ($configured_offer
->isDisplayInclusive()) {
return TRUE;
}
}
return FALSE;
}
assert($offer instanceof ShipmentPromotionOfferInterface);
return $offer
->isDisplayInclusive();
});
return $promotions;
}