protected function FedEx::getFedExShipment in Commerce FedEx 8
Gets a RequestedShipment object for FedEx.
Parameters
\Drupal\commerce_shipping\Entity\ShipmentInterface $shipment: The shipment.
Return value
\NicholasCreativeMedia\FedExPHP\Structs\RequestedShipment The RequestedShipment object.
1 call to FedEx::getFedExShipment()
- FedEx::getRateRequest in src/
Plugin/ Commerce/ ShippingMethod/ FedEx.php - Gets a rate request object for FedEx.
File
- src/
Plugin/ Commerce/ ShippingMethod/ FedEx.php, line 796
Class
- FedEx
- Provides the FedEx shipping method.
Namespace
Drupal\commerce_fedex\Plugin\Commerce\ShippingMethodCode
protected function getFedExShipment(ShipmentInterface $shipment) {
$line_items = $this
->getRequestedPackageLineItems($shipment);
if ($this->configuration['options']['packaging'] == static::PACKAGE_CALCULATE) {
$count = 0;
foreach ($line_items as $line_item) {
$count += $line_item
->getGroupPackageCount();
}
}
else {
$count = count($line_items);
}
/** @var \Drupal\address\AddressInterface $recipient_address */
$recipient_address = $shipment
->getShippingProfile()
->get('address')
->first();
$shipper_address = $shipment
->getOrder()
->getStore()
->getAddress();
$fedex_shipment = new RequestedShipment();
$fedex_shipment
->setShipper($this
->getAddressForFedEx($shipper_address))
->setRecipient($this
->getAddressForFedEx($recipient_address))
->setRequestedPackageLineItems($line_items)
->setPackageCount($count)
->setPreferredCurrency($shipment
->getOrder()
->getStore()
->getDefaultCurrencyCode())
->setDropoffType($this->configuration['options']['dropoff'])
->setRateRequestTypes([
$this->configuration['options']['rate_request_type'],
]);
if ($this->configuration['options']['insurance']) {
$fedex_shipment
->setTotalInsuredValue(new Money($shipment
->getTotalDeclaredValue()
->getCurrencyCode(), $shipment
->getTotalDeclaredValue()
->getNumber()));
}
return $fedex_shipment;
}