Skip to content
Snippets Groups Projects

Issue #2982938: Display order total in cart block

Open tonytheferg requested to merge issue/commerce-2982938:2982938-display-order-total into 3.x
Files
3
@@ -2,6 +2,7 @@
namespace Drupal\commerce_cart\Plugin\Block;
use Drupal\commerce_price\Price;
use Drupal\Core\Block\Attribute\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Cache\Cache;
@@ -114,7 +115,11 @@ class CartBlock extends BlockBase implements ContainerFactoryPluginInterface {
return $cart->hasItems() && $cart->cart->value;
});
/** @var \Drupal\commerce_store\Entity\StoreInterface $store */
$store = $this->entityTypeManager->getStorage('commerce_store')->loadDefault();
$count = 0;
$total = new Price('0', !empty($store) ? $store->getDefaultCurrencyCode() : 'USD');
$cart_views = [];
if (!empty($carts)) {
$cart_views = $this->getCartViews($carts);
@@ -122,6 +127,9 @@ class CartBlock extends BlockBase implements ContainerFactoryPluginInterface {
foreach ($cart->getItems() as $order_item) {
$count += (int) $order_item->getQuantity();
}
if ($cart_total = $cart->getTotalPrice()) {
$total = $total->add($cart_total);
}
$cacheable_metadata->addCacheableDependency($cart);
}
}
@@ -160,6 +168,7 @@ class CartBlock extends BlockBase implements ContainerFactoryPluginInterface {
'contexts' => ['cart'],
],
'#dropdown' => $this->configuration['dropdown'],
'#total' => $total,
];
}
Loading