You are here

protected function DryIcePlugin::isDryIceItem in Commerce FedEx 8

Determine whether a shipment item requires dry ice shipping or not.

Parameters

\Drupal\commerce_shipping\ShipmentItem $shipment_item: The shipment item.

string $type: The type, 'domestic' or 'intl' depending on the shipping distance.

Return value

bool true if the shipment item requires dry ice shipping.

Throws

\Exception If the provided $type is not of type 'string'.

4 calls to DryIcePlugin::isDryIceItem()
DryIcePlugin::adjustPackage in modules/dry_ice/src/Plugin/Commerce/FedEx/DryIcePlugin.php
Adjust a package based on the items, shipment and profile.
DryIcePlugin::isDryIceBox in modules/dry_ice/src/Plugin/Commerce/FedEx/DryIcePlugin.php
Determine whether a droup of shipment items requires dry ice shipping.
DryIcePlugin::splitPackage in modules/dry_ice/src/Plugin/Commerce/FedEx/DryIcePlugin.php
Function splitPackage.
DryIcePlugin::verifyPackage in modules/dry_ice/src/Plugin/Commerce/FedEx/DryIcePlugin.php
Verified a package has all dry ic eor non-dry ice items.

File

modules/dry_ice/src/Plugin/Commerce/FedEx/DryIcePlugin.php, line 271

Class

DryIcePlugin
Provides the Fedex Dry Ice Service.

Namespace

Drupal\commerce_fedex_dry_ice\Plugin\Commerce\FedEx

Code

protected function isDryIceItem(ShipmentItem $shipment_item, $type) {
  if (!is_string($type)) {
    $varType = gettype($type);
    throw new \Exception("Shipment type must be string. {$varType} given.");
  }
  $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();
  return $purchased_entity
    ->hasField('fedex_dry_ice_' . $type) && !$purchased_entity
    ->get('fedex_dry_ice_' . $type)
    ->isEmpty() && $purchased_entity
    ->get('fedex_dry_ice_' . $type)
    ->first()
    ->getValue()['value'] == 1;
}