/**
  * @role update
  */
 public function updateAddress()
 {
     $validator = $this->createUserAddressFormValidator();
     if ($validator->isValid()) {
         $order = CustomerOrder::getInstanceByID((int) $this->request->get('orderID'), true, array('ShippingAddress' => 'UserAddress', 'BillingAddress' => 'UserAddress', 'State'));
         $address = UserAddress::getInstanceByID('UserAddress', (int) $this->request->get('ID'), true, array('State'));
         $history = new OrderHistory($order, $this->user);
         $address->loadRequestData($this->request);
         $address->save();
         $history->saveLog();
         if (!$this->request->get('ID')) {
             if (!$order->billingAddress->get()) {
                 $order->billingAddress->set($address);
             }
             if (!$order->shippingAddress->get()) {
                 $order->shippingAddress->set($address);
             }
             $order->save();
         }
         return new JSONResponse(array('address' => $address->toArray()), 'success', $this->translate('_order_address_was_successfully_updated'));
     } else {
         return new JSONResponse(array('errors' => $validator->getErrorList()), 'failure', $this->translate('_error_updating_order_address'));
     }
 }