Are there get/set functions/methods for all line item and order properties?

I find myself manipulating line items thus:

$line_item->commerce_unit_price['und'][0]['currency_code'] = $whatever;

I was thinking there must be a better way to (ie. without addressing array members?) My concern is that the structure may change as Commerce develops.

1 Answer 1


What you're doing is correct for Commerce 1.x. Drupal 7 just uses stdClass objects for entities, no methods. Fortunately Commerce 1.x isn't seeing any significant changes - any time we make an API change it will be heavily noted in the change log of a new release. Additionally, Commerce 2.x on Drupal 8 is actually able to use robust classes for entities, so the future is brighter.

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.