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:

uc_order_edit_form_submit($form, $form_state);

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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

SilviuChingaru’s picture

SilviuChingaru’s picture

Status: Active » Needs review
SilviuChingaru’s picture

Assigned: SilviuChingaru » Unassigned
Status: Needs review » Needs work
SilviuChingaru’s picture

Still present in RC4...

TR’s picture

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.

SilviuChingaru’s picture

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. ;-) :-)

SilviuChingaru’s picture

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".

longwave’s picture

Status: Postponed » Closed (duplicate)
longwave’s picture

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.

SilviuChingaru’s picture

Status: Needs review » Needs work
FileSize
2 KB

@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.

SilviuChingaru’s picture

Status: Needs work » Needs review
SilviuChingaru’s picture

SilviuChingaru’s picture

Status: Needs work » Active
end user’s picture

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

> "happy accident" Bob Ross ftw!

SilviuChingaru’s picture

Still no progress on this... :(

Please help.

SilviuChingaru’s picture

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

This is the right title for this topic.

SilviuChingaru’s picture

I wander is just me bothered by this bug?!

SilviuChingaru’s picture

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.

SilviuChingaru’s picture

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:

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:

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

ajax callback looks like this:

 /**
 * 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:

/**
 * 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?

SilviuChingaru’s picture

Nevermind... fixed.

SilviuChingaru’s picture

Assigned: Unassigned » SilviuChingaru
SilviuChingaru’s picture

Status: Active » Needs review
FileSize
3.4 KB

Patch...

SilviuChingaru’s picture

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.

SilviuChingaru’s picture

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.

SilviuChingaru’s picture

Assigned: SilviuChingaru » Unassigned
Status: Needs work » Needs review
FileSize
4.04 KB

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...

SilviuChingaru’s picture

Title: Admin order data not saved when shipping quote is applied to order » Admin 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.

SilviuChingaru’s picture

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?

SilviuChingaru’s picture

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.

longwave’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
3.56 KB

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.

longwave’s picture

Status: Needs review » Fixed

Committed #29

Status: Fixed » Closed (fixed)

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

SilviuChingaru’s picture

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