protected function CartBlockBase::getTotal in Commerce Cart Blocks 8
Gets the total price of the carts.
1 call to CartBlockBase::getTotal()
- CartBlockBase::getTotalText in src/
Plugin/ Block/ CartBlockBase.php - Gets the total price as a formatted string.
File
- src/
Plugin/ Block/ CartBlockBase.php, line 228
Class
- CartBlockBase
- CartBlockBase class.
Namespace
Drupal\commerce_cart_blocks\Plugin\BlockCode
protected function getTotal() {
$carts = $this
->getCarts();
/** @var \Drupal\commerce_order\Entity\OrderInterface $firstCart */
$firstCart = array_shift($carts);
if (!empty($firstCart)) {
$price = $firstCart
->getTotalPrice();
foreach ($carts as $cart_id => $cart) {
$price
->add($cart
->getTotalPrice());
}
}
else {
$price = $this
->createPrice(0);
}
return $price;
}