When you create a new order from admin/store/orders/create is you fill the order and before hitting "Submit changes" you apply a shipping quote to that order all order data is not saved.

This happens because "Get shipping quote" form calls submit form uc_quote_apply_quote_to_order($form, &$form_state) but never pass back the $form_state to uc_order_edit_form_submit($form, $form_state).

A simple workaround is to put a line like this:

<?php
uc_order_edit_form_submit
($form, $form_state);
?>

in uc_quote_apply_quote_to_order($form, &$form_state) patch will follow.

Files: 
CommentFileSizeAuthor
#29 1413372-admin-order-shipping-ajax.patch3.56 KBlongwave
PASSED: [[SimpleTest]]: [MySQL] 2,453 pass(es).
[ View ]
#25 ubercart_uc_quote_apply_shipping_using_ajax-1413372-1.patch4.04 KBfiftyz
PASSED: [[SimpleTest]]: [MySQL] 1,684 pass(es).
[ View ]
#22 ubercart_uc_quote_apply_shipping_using_ajax-1413372-0.patch3.4 KBfiftyz
PASSED: [[SimpleTest]]: [MySQL] 1,943 pass(es).
[ View ]
#10 undefined_method_and_rate-1410302-3.patch2 KBfiftyz
PASSED: [[SimpleTest]]: [MySQL] 1,940 pass(es).
[ View ]
#1 lose_data_on_apply_quote-1413372-2.patch409 bytesfiftyz
PASSED: [[SimpleTest]]: [MySQL] 1,898 pass(es).
[ View ]

Comments

StatusFileSize
new409 bytes
PASSED: [[SimpleTest]]: [MySQL] 1,898 pass(es).
[ View ]

Status:Active» Needs review

Assigned:fiftyz» Unassigned
Status:Needs review» Needs work

Still present in RC4...

Again, an open issue is by definition not fixed yet. Please read http://drupal.org/node/156119 if you're unsure what the issue statuses mean. If you want to help get this fixed, then submit a working patch for review.

As you can see in all my posts I'm trying to fix every bug that I can so do not understand the attitude. I thought maybe a "happy accident" fixed the bug. ;-) :-)

Status:Needs work» Postponed

This should be fixed when #1410302: Notice: Undefined index: method and rate in uc_shipping_shipment_edit(); is fixed. If the order will not reload the data will be "saved".

Status:Postponed» Closed (duplicate)

Status:Closed (duplicate)» Needs work

Reopening, as this is technically a separate problem; the other issue is a display error which could occur when there is genuinely no valid quote attached to the order.

Status:Needs review» Needs work
StatusFileSize
new2 KB
PASSED: [[SimpleTest]]: [MySQL] 1,940 pass(es).
[ View ]

@longwave
Ok, so my patch is better putted here. I don't know from where $form['line-items'] are generated because my patch, the one attached, is working both ways:
- it modifies order form id='order-line-items' but only the Total. Also if i put an empty ajax_command_replace('#order-line-items', '') the div content is erased.
- the $form var (dpm($form)) is getting the new quote values but the textfield values and amount are not changing so if you click Submit changes the shipping line item is saved to database with the label and ammount of first loaded shipping method. The last selected shipping method applied in shipping form is also saved to order.

So, I'm thinking that there is a little problem with the ajax callback or line_items are cached somewhere?

Please help, I worked on this patch for one day and still no solution... At least a clue where to look for docs or something.

Status:Needs work» Needs review

Status:Needs work» Active

Title:Admin order shipping method not set and order data reset when shipping quote applied to orderAdmin order data not saved when shipping quote is applied to order
Status:Needs review» Active

> "happy accident" Bob Ross ftw!

Still no progress on this... :(

Please help.

Title:Admin order data not saved when shipping quote is applied to orderAdmin order shipping method not set and order data reset when shipping quote applied to order

This is the right title for this topic.

I wander is just me bothered by this bug?!

I'm willing to donate to anyone who fix this issue. Just tell me how much and if we agree I'll make the donation when patch is ready. I am desperate to solve this issue.

I managed so far to make both shipping buttons use ajax (no order reload and lose unsaved data). Even the shipping method is saved ok to the order BUT the line item 'shipping' is not changed via ajax and if we click save the right shipping method is selected but it gets the name of first form build shipping method.
What I did so far:

<?php
function uc_order_pane_quotes($op, $order, &$form = NULL, &$form_state = NULL) {
  ...
       
$form['quotes']['quotes']['add_quote'] = array(
         
'#type' => 'submit',
         
'#value' => t('Apply to order'),
         
'#submit' => array('uc_quote_apply_quote_to_order'),
         
'#ajax' => array(
           
'callback' => 'uc_quote_order_update_rates',
           
'effect' => 'slide',
           
'progress' => array(
             
'message' => t('Applying quotes...'),
            ),
          ),
        );
      }
...
}
?>

The quote button should be called via ajax too so we need to add the following to original function:

<?php
'#ajax' => array(
 
'callback' => 'uc_quote_order_update_rates',
 
'progress' => array(
   
'message' => t('Applying quotes...'),
  ),
),
?>

ajax callback looks like this:

<?php
/**
* AJAX callback for reseting shipping rates.
*/
function uc_quote_order_update_rates($form, $form_state) {
 
// Reset shipping form
 
$commands[] = ajax_command_replace('#quote', drupal_render($form['quotes']['quotes']));
 
$commands[] = ajax_command_prepend('#quote', theme('status_messages'));
 
// Update order line items
 
$commands[] = ajax_command_replace('#order-line-items', drupal_render($form['line_items']));
 
$commands[] = ajax_command_prepend('#order-line-items', theme('status_messages'));
  return array(
'#type' => 'ajax', '#commands' => $commands);
}
?>

We need to instruct drupal_process_form to rebuild the form not submit it so we add the following:

<?php
/**
* Ajax callback: Manually applies a shipping quote to an order.
*/
function uc_quote_apply_quote_to_order($form, &$form_state) {
  ...
 
$form_state['rebuild'] = TRUE;
 
$form_state['quote_requested'] = FALSE;
}
?>

Is working so far but order line items don't get updated via ajax. Why? Where could be the problem?

Nevermind... fixed.

Assigned:Unassigned» fiftyz

Status:Active» Needs review
StatusFileSize
new3.4 KB
PASSED: [[SimpleTest]]: [MySQL] 1,943 pass(es).
[ View ]

Patch...

Status:Needs review» Needs work

Still has a bug:

If admin change qty of a product and click GET SHIPING QUOTES button without saving the order first, the weight shipping is not re-calculated. The problem I think should be fixed by adding the submit form function in #submit array of GET SHIPPING QUOTE. I'll try if it works and post a patch.

I think better will be to apply shipping quotes on $form_state order products and qty... I'll try this in order to close this issue.

Assigned:fiftyz» Unassigned
Status:Needs work» Needs review
StatusFileSize
new4.04 KB
PASSED: [[SimpleTest]]: [MySQL] 1,684 pass(es).
[ View ]

And the final patch in order to close this issue...
If user edit an order from admin page, he changes quantities of one or more product and then click on "Get shipping quotes" button without clicking "Save changes" button, the shipping quotes are calculated based on new changes. The order is not saved when he clicks "Get shipping quotes" but when he click "Apply to order", the order is saved and the shipping line item is updated as it should.

Should we save the order on "Apply to order" or just update shipping line item and save the order only when user clicks "Submit changes"???? Normally, I think, all changes to the order should be made on "Submit changes" but this wasn't the original behavior of "Apply to order" button. Waiting for suggestions...

Title:Admin order data not saved when shipping quote is applied to orderAdmin order shipping method not set and order data reset when shipping quote applied to order
Status:Active» Needs review

Bump... The last patch is ready for commit. I'm using it on a production site and no bug with it.

I don't understand why this patch didn't make it to 3.1 release?! Is not so important the admin order part of ubercart or what?

Status:Needs review» Reviewed & tested by the community

I've tested this patch for more than 5 months now and I think is ready for commit.

Status:Reviewed & tested by the community» Needs review
StatusFileSize
new3.56 KB
PASSED: [[SimpleTest]]: [MySQL] 2,453 pass(es).
[ View ]

I simplified the patch a little and changed some comments, but otherwise this looks pretty good - thanks for working on it. And sorry for taking so long to get around to reviewing it, I wanted to try and clean up some of the surrounding code at the same time, but I think that's for another issue; the order edit form, line items and shipping quotes code are some of the ugliest parts of Ubercart, and this touches all of those.

Status:Needs review» Fixed

Committed #29

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Thank you... it was about time... :-)