Drupal 8 get cart item programmatically I need to create pdf of user's cart items with custom header &amp; footer. I decide to create custom module in which I can get cart items details. But I have no idea about how to do this? I have tried:

$store_id = 1;
$order_type = 'default';
$cart_manager = \Drupal::service('commerce_cart.cart_manager');
$cart_provider = \Drupal::service('commerce_cart.cart_provider');
$entity_manager = \Drupal::entityManager();
$store = $entity_manager-&gt;getStorage('commerce_store')-&gt;load($store_id); 
$cart = $cart_provider-&gt;getCart($order_type, $store);
foreach ($cart-&gt; getItems() as $order_item) {
    foreach($order_item-&gt;getPurchasedEntity() as $purchased_entity){
        print_r($purchased_entity);
    }    
}


But it gives an array like 

Drupal\commerce_product\Entity\ProductVariation Object
(
[values:protected] =&gt; Array
    (
        [variation_id] =&gt; Array
            (
                [x-default] =&gt; 432
            )

        [type] =&gt; Array
            (
                [x-default] =&gt; product_variations
            )

        [uuid] =&gt; Array
            (
                [x-default] =&gt; 87d27a77-4bc1-40ff-b3cf-ad3e949ce1b3
            )

        [langcode] =&gt; Array
            (
                [x-default] =&gt; en
            )

        [status] =&gt; Array
            (
                [x-default] =&gt; 1
            )

        [uid] =&gt; Array
            (
                [x-default] =&gt; 9
            )

        [product_id] =&gt; Array
            (
                [x-default] =&gt; 65
            )

        [sku] =&gt; Array
            (
                [x-default] =&gt; xx-uua
            )
        [price] =&gt; Array
            (
                [x-default] =&gt; Array
                    (
                        [number] =&gt; 22.000000
                        [currency_code] =&gt; USD
                    )

            )
        [field_order_no] =&gt; Array
            (
                [x-default] =&gt; Array
                    (
                        [0] =&gt; Array
                            (
                                [value] =&gt; PE-5070
                            )

                    )

            )


And many more protected objects. 
I know I can get quantity, title &amp; price easily using drupal function but how can I get few custom details from above array like field_order_no in above array, I have some unique attribute assigned to variation that I need to display in pdf?
As the top line suggests $purchased_entity is of of type "Drupal\commerce_product\Entity\ProductVariation" which is basically an entity.

All entities have a -&gt;get('field_name') method.

So for your example to get 'field_order_no' you would do

$order_no = $purchased_entity-&gt;get('field_order_no')-&gt;getValue();


You can retrieve the value of any field via the -&gt;getValue() method which returns an array.