public function Order::recalculateTotalPrice in Commerce Core 8.2
Recalculates the order total price.
Return value
$this
Overrides OrderInterface::recalculateTotalPrice
6 calls to Order::recalculateTotalPrice()
- Order::addAdjustment in modules/
order/ src/ Entity/ Order.php - Adds an adjustment.
- Order::addItem in modules/
order/ src/ Entity/ Order.php - Adds an order item.
- Order::removeAdjustment in modules/
order/ src/ Entity/ Order.php - Removes an adjustment.
- Order::removeItem in modules/
order/ src/ Entity/ Order.php - Removes an order item.
- Order::setAdjustments in modules/
order/ src/ Entity/ Order.php - Sets the adjustments.
File
- modules/
order/ src/ Entity/ Order.php, line 437
Class
- Order
- Defines the order entity class.
Namespace
Drupal\commerce_order\EntityCode
public function recalculateTotalPrice() {
/** @var \Drupal\commerce_price\Price $total_price */
$total_price = NULL;
foreach ($this
->getItems() as $order_item) {
if ($order_item_total = $order_item
->getTotalPrice()) {
$total_price = $total_price ? $total_price
->add($order_item_total) : $order_item_total;
}
}
if ($total_price) {
$adjustments = $this
->collectAdjustments();
if ($adjustments) {
/** @var \Drupal\commerce_order\AdjustmentTransformerInterface $adjustment_transformer */
$adjustment_transformer = \Drupal::service('commerce_order.adjustment_transformer');
$adjustments = $adjustment_transformer
->combineAdjustments($adjustments);
$adjustments = $adjustment_transformer
->roundAdjustments($adjustments);
foreach ($adjustments as $adjustment) {
if (!$adjustment
->isIncluded()) {
$total_price = $total_price
->add($adjustment
->getAmount());
}
}
}
}
$this->total_price = $total_price;
return $this;
}