0

I try to get order variables using devel module from inside custom order template page--admin--commerce--orders__%.tpl.php.

I use code $order = commerce_order_load(123);

Question: is it possible not to load full order again and get the variables ? (assuming that I am on order page, the variables should be loaded anyways correct?) Thank you for explanation.

0

Don't worry about it.

Loaded entities are cached for at least that request, so you're either loading up an entity which hasn't been loaded yet, in which case the DB load is inevitable, or you're simply retrieving the already-loaded entity from static cache.

As an aside, don't load up entities in template files - always do it in a preprocess hook and pass the variable in.

| improve this answer | |
1

You need to use commerce_order_load to load the order with all the data. If the order already has been loaded somewhere else on the page, the order won't be loaded twice, but the order will be fetched from static cache instead. So it's fine to load the same order multiple times.

If you do need to clear the cache, (maybe you need to compare the order to what is in the datebase to see what has changed), then you can use use commerce_order_load_multiple or call entity_load directly.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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