I need to create pdf of user's cart items with custom header & 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->getStorage('commerce_store')->load($store_id);
$cart = $cart_provider->getCart($order_type, $store);
foreach ($cart-> getItems() as $order_item) {
foreach($order_item->getPurchasedEntity() as $purchased_entity){
print_r($purchased_entity);
}
}
But it gives an array like
Drupal\commerce_product\Entity\ProductVariation Object
(
[values:protected] => Array
(
[variation_id] => Array
(
[x-default] => 432
)
[type] => Array
(
[x-default] => product_variations
)
[uuid] => Array
(
[x-default] => 87d27a77-4bc1-40ff-b3cf-ad3e949ce1b3
)
[langcode] => Array
(
[x-default] => en
)
[status] => Array
(
[x-default] => 1
)
[uid] => Array
(
[x-default] => 9
)
[product_id] => Array
(
[x-default] => 65
)
[sku] => Array
(
[x-default] => xx-uua
)
[price] => Array
(
[x-default] => Array
(
[number] => 22.000000
[currency_code] => USD
)
)
[field_order_no] => Array
(
[x-default] => Array
(
[0] => Array
(
[value] => PE-5070
)
)
)
And many more protected
objects.
I know I can get quantity, title & 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?