class LateOrderProcessor in Commerce Shipping 8.2
Completes the order refresh process for shipments.
Saves any previously modified shipments. Transfers the shipment amount and adjustments to the order.
Runs after other order processors (promotion, tax, etc).
Hierarchy
- class \Drupal\commerce_shipping\LateOrderProcessor implements OrderProcessorInterface
Expanded class hierarchy of LateOrderProcessor
See also
\Drupal\commerce_shipping\EarlyOrderProcessor
1 string reference to 'LateOrderProcessor'
1 service uses LateOrderProcessor
File
- src/
LateOrderProcessor.php, line 19
Namespace
Drupal\commerce_shippingView source
class LateOrderProcessor implements OrderProcessorInterface {
/**
* The shipping order manager.
*
* @var \Drupal\commerce_shipping\ShippingOrderManagerInterface
*/
protected $shippingOrderManager;
/**
* Constructs a new LateOrderProcessor object.
*
* @param \Drupal\commerce_shipping\ShippingOrderManagerInterface $shipping_order_manager
* The shipping order manager.
*/
public function __construct(ShippingOrderManagerInterface $shipping_order_manager) {
$this->shippingOrderManager = $shipping_order_manager;
}
/**
* {@inheritdoc}
*/
public function process(OrderInterface $order) {
if (!$this->shippingOrderManager
->hasShipments($order)) {
return;
}
/** @var \Drupal\commerce_shipping\Entity\ShipmentInterface[] $shipments */
$shipments = $order
->get('shipments')
->referencedEntities();
$single_shipment = count($shipments) === 1;
foreach ($shipments as $shipment) {
if ($shipment
->hasTranslationChanges()) {
$shipment
->save();
}
if ($amount = $shipment
->getAmount()) {
// Shipments without an amount are incomplete / unrated.
$order
->addAdjustment(new Adjustment([
'type' => 'shipping',
'label' => $single_shipment ? t('Shipping') : $shipment
->getTitle(),
'amount' => $amount,
'source_id' => $shipment
->id(),
]));
foreach ($shipment
->getAdjustments() as $adjustment) {
if ($adjustment
->isLocked()) {
// Locked shipment adjustments must be transferred unlocked
// so that they're cleared at the beginning of order refresh.
$adjustment = new Adjustment([
'locked' => FALSE,
] + $adjustment
->toArray());
}
$order
->addAdjustment($adjustment);
}
}
}
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LateOrderProcessor:: |
protected | property | The shipping order manager. | |
LateOrderProcessor:: |
public | function |
Processes an order. Overrides OrderProcessorInterface:: |
|
LateOrderProcessor:: |
public | function | Constructs a new LateOrderProcessor object. |