protected function CartBlock::getCartViews in Commerce Core 8.2
Gets the cart views for each cart.
Parameters
\Drupal\commerce_order\Entity\OrderInterface[] $carts: The cart orders.
Return value
array An array of view ids keyed by cart order ID.
1 call to CartBlock::getCartViews()
- CartBlock::build in modules/
cart/ src/ Plugin/ Block/ CartBlock.php - Builds the cart block.
File
- modules/
cart/ src/ Plugin/ Block/ CartBlock.php, line 176
Class
- CartBlock
- Provides a cart block.
Namespace
Drupal\commerce_cart\Plugin\BlockCode
protected function getCartViews(array $carts) {
$cart_views = [];
if ($this->configuration['dropdown']) {
$order_type_ids = array_map(function ($cart) {
return $cart
->bundle();
}, $carts);
$order_type_storage = $this->entityTypeManager
->getStorage('commerce_order_type');
$order_types = $order_type_storage
->loadMultiple(array_unique($order_type_ids));
$available_views = [];
foreach ($order_type_ids as $cart_id => $order_type_id) {
/** @var \Drupal\commerce_order\Entity\OrderTypeInterface $order_type */
$order_type = $order_types[$order_type_id];
$available_views[$cart_id] = $order_type
->getThirdPartySetting('commerce_cart', 'cart_block_view', 'commerce_cart_block');
}
foreach ($carts as $cart_id => $cart) {
$cart_views[] = [
'#prefix' => '<div class="cart cart-block">',
'#suffix' => '</div>',
'#type' => 'view',
'#name' => $available_views[$cart_id],
'#arguments' => [
$cart_id,
],
'#embed' => TRUE,
];
}
}
return $cart_views;
}