public function CartUnifier::getMainCarts in Commerce Combine Carts 8
Returns main carts, one per order type.
Parameters
\Drupal\user\UserInterface $user: The user.
Return value
\Drupal\commerce_order\Entity\OrderInterface[]|NULL The main carts for the user, or NULL if there is no cart.
2 calls to CartUnifier::getMainCarts()
- CartUnifier::assignCart in src/
CartUnifier.php - Assign a cart to a user, possibly moving items to the user's main cart.
- CartUnifier::combineUserCarts in src/
CartUnifier.php - Combines all of a user's carts into their main cart.
File
- src/
CartUnifier.php, line 50
Class
Namespace
Drupal\commerce_combine_cartsCode
public function getMainCarts(UserInterface $user) {
// Clear cart cache so that newly assigned carts are available.
$this->cartProvider
->clearCaches();
$carts = $this->cartProvider
->getCarts($user);
if (empty($carts)) {
return NULL;
}
// Loop over carts. If there are several of the same type, we overwrite it
// with the latest one.
$carts_per_type = [];
foreach ($carts as $cart) {
$carts_per_type[$cart
->bundle()] = $cart;
}
return $carts_per_type;
}