public function DangerousGoodsPlugin::adjustPackage in Commerce FedEx 8
Adjust a package based on the items, shipment and profile.
Parameters
\NicholasCreativeMedia\FedExPHP\Structs\RequestedPackageLineItem $package: The package to adjust.
array $items: An array of shipment items.
\Drupal\commerce_shipping\Entity\ShipmentInterface $shipment: The shipment.
Return value
\NicholasCreativeMedia\FedExPHP\Structs\RequestedPackageLineItem The adjusted Package.
Overrides FedExPluginBase::adjustPackage
File
- modules/
dangerous/ src/ Plugin/ Commerce/ FedEx/ DangerousGoodsPlugin.php, line 60
Class
- DangerousGoodsPlugin
- Providex the FedEx Dangerous Goods Service Plugin.
Namespace
Drupal\commerce_fedex_dangerous\Plugin\Commerce\FedExCode
public function adjustPackage(RequestedPackageLineItem $package, array $shipment_items, ShipmentInterface $shipment) {
$status = $this
->getDangerousStatus(reset($shipment_items));
if ($status === static::NOT_DANGEROUS) {
return $package;
}
$special_services_requested = $package
->getSpecialServicesRequested();
if (empty($special_services_requested)) {
$special_services_requested = new PackageSpecialServicesRequested();
}
$special_services_requested
->addToSpecialServiceTypes(PackageSpecialServiceType::VALUE_DANGEROUS_GOODS);
$dangerous_goods_detail = $special_services_requested
->getDangerousGoodsDetail();
if (empty($dangerous_goods_detail)) {
$dangerous_goods_detail = new DangerousGoodsDetail();
}
$dangerous_goods_detail
->setAccessibility($status);
$special_services_requested
->setDangerousGoodsDetail($dangerous_goods_detail);
$package
->setSpecialServicesRequested($special_services_requested);
return $package;
}