I want to get:
- Order ID for the current user;
- All product variation ID from the current users cart;
- Prices for product variations;
- Images;
- Titles;
I have the following:
$store_id = 1;
$order_type = 'default';
$entity_manager = \Drupal::entityManager();
$cart_manager = \Drupal::service('commerce_cart.cart_manager');
$cart_provider = \Drupal::service('commerce_cart.cart_provider');
$store = $entity_manager->getStorage('commerce_store')->load($store_id);
$cart = $cart_provider->getCart($order_type, $store);
if(isset($cart)){
$itemNum = count($cart->getItems());
($itemNum > 0) ? $variables['items_in_cart'] = $itemNum : '';
}
$cart .= 'Subtotal: '.$cart->getSubtotalPrice();
$cart .= '<br>Total price: '.$cart->getTotalPrice();
$cart .= '<br>Created: '.$cart->getCreatedTime();
$cart .= '<br>Customer id: '.$cart->getCustomerId();
$cart .= '<br>Email: '.$cart->getEmail();
$cart .= '<br>IP address: '.$cart->getIpAddress();
$cart .= '<br>Item num. in cart: '.$itemNum;