Hi,

I am confusing why the comments not in the order object?

Then another problem is when you update an order in the admin order pane, to add a new comment, then add a CA to send out a email with the last comment, the comment is always not the new added comment.
As the CA action triggered before the new comment been save to the database.

Then why the ca action tirgger not after the whole order get updated or at least should be wait until the new comment save to database?

Thanks

CommentFileSizeAuthor
#8 order_comment_ca_trigger_order.patch1.37 KBwqmeng

Comments

AlexisWilke’s picture

Category: bug » support

wqmeng,

Note that you can change the order in which events occur by changing their weight. That may help you?

In regard to comments, they are separate because it is a 1 to many (1 order many comments.) Therefore, a separate table was created for the comments.

Thank you.
Alexis

wqmeng’s picture

Category: support » bug

Here is the trigger where been called.


/**
 * @see uc_order_view_update_form()
 */
function uc_order_view_update_form_submit($form, &$form_state) {
  global $user;

  if ($form_state['values']['status'] != $form_state['values']['current_status']) {
    if (uc_order_update_status($form_state['values']['order_id'], $form_state['values']['status'])) {    //  <<<============= Here the CA action will be invoked.
      if (is_null($form_state['values']['order_comment']) || strlen($form_state['values']['order_comment']) == 0) {
        uc_order_comment_save($form_state['values']['order_id'], $user->uid, '-', 'order', $form_state['values']['status'], $form_state['values']['notify']);
      }
    }
  }

  if (!is_null($form_state['values']['order_comment']) && strlen(trim($form_state['values']['order_comment'])) > 0) {   <<=========  Here save the new comment .
    uc_order_comment_save($form_state['values']['order_id'], $user->uid, $form_state['values']['order_comment'], 'order', $form_state['values']['status'], $form_state['values']['notify']);
  }

  if (!is_null($form_state['values']['admin_comment']) && strlen(trim($form_state['values']['admin_comment'])) > 0) {
    uc_order_comment_save($form_state['values']['order_id'], $user->uid, $form_state['values']['admin_comment']);
  }

  // Let conditional actions send email if requested.
  if ($form_state['values']['notify']) {
    $order = uc_order_load($form_state['values']['order_id']);
    ca_pull_trigger('uc_order_status_email_update', $order);
  }

  drupal_set_message(t('Order updated.'));
}

So in this condition, that the new status changed, the CA action get called before the lastest comment been save to the database.
Change the status first or save the comment first? IMO, should be save the comment then save the status before the CA action.
As when the new status changed, you may need the lastest comment to explain Why the order status get changed, like send emails with the latested comment.

http://articlesforge.com/

Thanks

wqmeng’s picture

Hi, change the event weight will not do the work, please look my code posted here,

The order status get changed always before the new comment added to the database.

So if you add new CA actions code or just add a email send with the last comment, the comment is not the new added one.

You may test it with a order,
1) add a order status CA
2) add custom php code to display the last comment you load from database.
3) update the order status to get the result

You will find that the last comment alway is the last comment before you add the new comment in the admin order pane.

I mean add order comment not admin comment.

Thanks

http://articlesforge.com/

AlexisWilke’s picture

Did you try to move the 1st if() after the 3rd one? Does that work for you? If so, great, then post a patch.

Thank you.
Alexis

wqmeng’s picture

Hi, I am now testing on it, when finished I will post a patch here.

wqmeng’s picture

Hello,

As #4, move the 1st if() after the 3rd one? Does that work for you? If so, great, then post a patch.

Will works, I have custom codes in this function, so someone may post a patch here,

Thanks

http://articlesforge.com/

wqmeng’s picture

StatusFileSize
new1.37 KB

Here the patch.

longwave’s picture

Status: Active » Fixed

Fixed in both branches.

Status: Fixed » Closed (fixed)

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