I have been trying for some time to figure out how Drupal Commerce uses the commerce_line_items field. It looks to me like this is the field that provides the link between a commerce line item and the order to which it is attached, so that if all you had was the order_id, you wouldn't have to query the entire commerce_line_items table, but could just look at this field. However, I cannot figure out how or where this field is defined, and where its values are set. If anybody can get me pointed in the right direction, I will happily write some documentation so that others may understand what is going on.

1 Answer 1


This answer refers to the Drupal 7 version, but I assume it's similar for D8.

The commerce_line_items field is a field of type commerce_line_item_reference (basically a reference field) that is defined and instantiated inside the function commerce_order_configure_order_type, in the file commerce_order.module.

This field of unlimited cardinality stores references to each of the line items in an order. Think of the line items as basically each of the "lines" in an order or invoice that reference a specific product, its quantity, price, and total price etc.

The values of the commerce_line_items field are initially set in the commerce_cart.module file, inside the commerce_cart_product_add function (basically when you add a product to the cart), in line 1377.

All of this information can be glanced by studying these files.


I'm not sure I'm understanding where you are going with this question, but given your recent edition, yes, you can access the values of the line items by using, for example, an entity_metadata_wrapper, which will allow you to navigate the relationship to each line item and all its fields and properties. See this tutorial for entity_metadata_wrapper

  • IIRC it is a custom entity defined by Commerce.
    – Kevin
    Apr 29, 2017 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.