public function USPS::calculateRates in Commerce USPS 8
Calculates rates for the given shipment.
Parameters
\Drupal\commerce_shipping\Entity\ShipmentInterface $shipment: The shipment.
Return value
\Drupal\commerce_shipping\ShippingRate[] The rates.
Overrides ShippingMethodInterface::calculateRates
File
- src/
Plugin/ Commerce/ ShippingMethod/ USPS.php, line 78
Class
- USPS
- Provides the USPS shipping method.
Namespace
Drupal\commerce_usps\Plugin\Commerce\ShippingMethodCode
public function calculateRates(ShipmentInterface $shipment) {
// Only attempt to collect rates if an address exists on the shipment.
if ($shipment
->getShippingProfile()
->get('address')
->isEmpty()) {
return [];
}
// Only attempt to collect rates for US addresses.
if ($shipment
->getShippingProfile()
->get('address')->country_code != 'US') {
return [];
}
// Make sure a package type is set on the shipment.
$this
->setPackageType($shipment);
return $this->uspsRateService
->getRates($shipment, $this->parentEntity);
}