title: Magento update order shipping address
body: <p>At the end of the purchase, the user has the possibility to change your shipping address. Im trying to update this information, but it dosen't work. This is my code:</p>
  
  <pre><code>$customer = Mage::getModel('customer/session')-&gt;getCustomer();
  $order = Mage::getSingleton('checkout/session')-&gt;getLastOrder();
  $postData = Mage::app()-&gt;getRequest()-&gt;getPost();
  
  $_new_address = array (
      'firstname' =&gt; $postData['nombre'],
      'lastname'  =&gt; $postData['apellidos'],
      'street'    =&gt; array ('0' =&gt; $postData['direccion']),
      'city'      =&gt; $postData['localidad'],
      'region_id' =&gt; $postData['provincia_id'],
      'region'    =&gt; '',
      'postcode'  =&gt; $postData['codigo_postal'],
      'country_id'=&gt; 'ES',
      'telephone' =&gt; $postData['telefono']
  );
  
  $customAddress = Mage::getModel('customer/address');
  $customAddress-&gt;setData($_new_address)
      -&gt;setCustomerId($customer-&gt;getId())
      -&gt;setIsDefaultBilling('1')
      -&gt;setIsDefaultShipping('1')
      -&gt;setSaveInAddressBook('1');
  
  // Save address
  try {
      $customAddress-&gt;save();
  } catch (Exception $e) {
      Mage::getSingleton('core/session')-&gt;addError($e-&gt;getMessage());
      header('Location: /');
      exit;
  }
  
  // Update the order
  try {
      $order-&gt;setShippingAddress($customAddress)-&gt;save();
  } catch (Exception $e) {
      Mage::getSingleton('core/session')-&gt;addError($e-&gt;getMessage());
      header('Location: /');
      exit;
  }
  </code></pre>
  
  <p>Can I update an order or is not allowed? Can anyone give me a tip?</p>