You are here

protected function DangerousGoodsPlugin::getDangerousStatus in Commerce FedEx 8

Returns the DG status of an item.

Parameters

\Drupal\commerce_shipping\ShipmentItem $shipment_item: The item to check.

Return value

mixed The DG status.

1 call to DangerousGoodsPlugin::getDangerousStatus()
DangerousGoodsPlugin::adjustPackage in modules/dangerous/src/Plugin/Commerce/FedEx/DangerousGoodsPlugin.php
Adjust a package based on the items, shipment and profile.

File

modules/dangerous/src/Plugin/Commerce/FedEx/DangerousGoodsPlugin.php, line 103

Class

DangerousGoodsPlugin
Providex the FedEx Dangerous Goods Service Plugin.

Namespace

Drupal\commerce_fedex_dangerous\Plugin\Commerce\FedEx

Code

protected function getDangerousStatus(ShipmentItem $shipment_item) {
  $storage = \Drupal::entityTypeManager()
    ->getStorage('commerce_order_item');

  /** @var \Drupal\commerce_order\Entity\OrderItemInterface $order_item */
  $order_item = $storage
    ->load($shipment_item
    ->getOrderItemId());
  $purchased_entity = $order_item
    ->getPurchasedEntity();
  if (!$purchased_entity
    ->hasField('fedex_dangerous_accessibility') || $purchased_entity
    ->get('fedex_dangerous_accessibility')
    ->isEmpty()) {
    return static::NOT_DANGEROUS;
  }
  return $purchased_entity
    ->get('fedex_dangerous_accessibility')->value;
}