How to access the order total amount in Drupal commerce? I'm trying to make a block with an image that would change when there is something in his or hger basket (empty basket image when basket is empty, full basket when it's full)
My understanding of PHP is weak, but I found this topic : 

http://www.drupalcommerce.org/discussions/787/simple-shopping-cart-summary

and I wrote that: 

&lt;?php
global $user;
$order = commerce_cart_order_load($user-&gt;uid);
$wrapper = entity_metadata_wrapper('commerce_order', $order);
$order_total = $wrapper-&gt;commerce_order_total-&gt;value();
if ($order_total['amount']&gt;0) echo ('&lt;a href="/twotrees/cart"&gt; &lt;img src="/sites/default/files/basketfull.png" &gt; &lt;/img&gt; &lt;/a&gt;');
else echo ('&lt;a href="/twotrees/cart"&gt; &lt;img src="/sites/default/files/basketempty.png" &gt; &lt;/img&gt; &lt;/a&gt;');
?&gt;


Now on my home server everything worked as expected. On the reomte one i got several show-stopping errors. 

If i put the whole thing, I get

EntityMetadataWrapperException: Invalid data value given. Be sure it matches the required data type and format. w EntityDrupalWrapper-&gt;set() (line 744 of /profiles/commerce_kickstart/modules/entity/includes/entity.wrapper.inc).


By trial and error, I detected that leaving the first two lines 

global $user;
$order = commerce_cart_order_load($user-&gt;uid);


are 'innocent'. It's the third one 

$wrapper = entity_metadata_wrapper('commerce_order', $order);


that generates the error. 
So actually it's the code from that commerce thread that seems to generate the error. To me it seems pretty innocent, though. 

As I said, I know very little about PHP, not to mention the internals of Drupal Commerce. I'd be grateful for any suggestions.
Try this

global $user;
$image = theme('image', array('path' =&gt; url('sites/default/files/basketempty.png', array('absolute' =&gt; TRUE))));
$order = commerce_cart_order_load($user-&gt;uid);

if ($order) {
  $wrapper = entity_metadata_wrapper('commerce_order', $order);
  $line_items = $wrapper-&gt;commerce_line_items;
  $total = commerce_line_items_total($line_items);
  if($total['amount']){ 
    $image = theme('image', array('path' =&gt; url('sites/default/files/basketfull.png', array('absolute' =&gt; TRUE))));
  }
}

echo l($image, 'twotrees/cart', array('html' =&gt; TRUE));