class ProfileSubscriber in Commerce Shipping 8.2
Hierarchy
- class \Drupal\commerce_shipping\EventSubscriber\ProfileSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of ProfileSubscriber
1 string reference to 'ProfileSubscriber'
1 service uses ProfileSubscriber
File
- src/
EventSubscriber/ ProfileSubscriber.php, line 8
Namespace
Drupal\commerce_shipping\EventSubscriberView source
class ProfileSubscriber implements EventSubscriberInterface {
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return [
'commerce_order.profiles' => [
'onProfiles',
],
];
}
/**
* Adds the shipping profile to the order profiles.
*
* The shipping profile is assumed to be the same for all shipments.
*
* @param \Drupal\commerce_order\Event\OrderProfilesEvent $event
* The order profiles event.
*/
public function onProfiles(OrderProfilesEvent $event) {
$order = $event
->getOrder();
if (!$order
->hasField('shipments')) {
return;
}
/** @var \Drupal\commerce_shipping\Entity\ShipmentInterface[] $shipments */
$shipments = $order
->get('shipments')
->referencedEntities();
$shipment = reset($shipments);
if ($shipment && $shipment
->getShippingProfile()) {
$event
->addProfile('shipping', $shipment
->getShippingProfile());
}
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ProfileSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
ProfileSubscriber:: |
public | function | Adds the shipping profile to the order profiles. |