You are here

public function ShippingMethodBase::selectRate in Commerce Shipping 8.2

Selects the given shipping rate for the given shipment.

Parameters

\Drupal\commerce_shipping\Entity\ShipmentInterface $shipment: The shipment.

\Drupal\commerce_shipping\ShippingRate $rate: The shipping rate.

Overrides ShippingMethodInterface::selectRate

File

src/Plugin/Commerce/ShippingMethod/ShippingMethodBase.php, line 247

Class

ShippingMethodBase
Provides the base class for shipping methods.

Namespace

Drupal\commerce_shipping\Plugin\Commerce\ShippingMethod

Code

public function selectRate(ShipmentInterface $shipment, ShippingRate $rate) {

  // Plugins can override this method to store additional information
  // on the shipment when the rate is selected (for example, the rate ID).
  $shipment
    ->setShippingMethodId($rate
    ->getShippingMethodId());
  $shipment
    ->setShippingService($rate
    ->getService()
    ->getId());
  $shipment
    ->setOriginalAmount($rate
    ->getOriginalAmount());
  $shipment
    ->setAmount($rate
    ->getAmount());
}