Get order items (in script)
Hi!
Which function can I get the order items? I need the quantity of items.
I use the commerce_order_load() function to get order data. But I can't find the items function(s).
Can Any help me? Which function could I use to get these data?
Comments
commerce_line_items_quantity
The function commerce_line_items_quantity()?
You might also consider
You might also consider http://drupal.org/project/devel and http://drupal.org/project/commerce_devel to navigate the structure of the order object. Once you find the items array, my guess is that you can count the number of items in the order using
<?php
echo count($object->array);
?>
count
How can I count the items?
$order->commerce_line_items[LANGUAGE_NONE][0]['line_item_id'] // first item
$order->commerce_line_items[LANGUAGE_NONE][1]['line_item_id'] // second item
// ...etc.
var_dump( $order->commerce_line_items[LANGUAGE_NONE] );
// result (for example 2 items):
// array(2) {
// [0]=>
// array(1) {
// ["line_item_id"]=>
// string(1) "3"
// }
// [1]=>
// array(1) {
// ["line_item_id"]=>
// string(1) "5"
// }
// }
ok
ok, it works. It gives integer value.