1

In code I am trying to mark an order as completed. I am doing this in hook_commerce_payment_order_paid_in_full

function my_module_commerce_payment_order_paid_in_full($transaction) {
  $orderid = $transaction->order_number;
  $order = commerce_order_load($orderid);
  commerce_order_status_update($order, 'completed');
}

However this does not seem to work. The state the call is at when going into this is processing

I also have the following 2 rules

{ "commerce_checkout_order_status_update" : {
    "LABEL" : "Update the order status on checkout completion",
    "PLUGIN" : "reaction rule",
    "TAGS" : [ "Commerce Checkout" ],
    "REQUIRES" : [ "commerce_order", "commerce_checkout" ],
    "ON" : [ "commerce_checkout_complete" ],
    "DO" : [
      { "commerce_order_update_state" : { "commerce_order" : [ "commerce-order" ], "order_state" : "pending" } }
    ]
  }
}

And

{ "rules_update_the_order_status_on_checkout_completion_if_payment_" : {
    "LABEL" : "Update the order status on checkout completion (if payment complete)",
    "PLUGIN" : "reaction rule",
    "WEIGHT" : "1",
    "TAGS" : [ "Commerce Checkout" ],
    "REQUIRES" : [ "commerce_payment", "commerce_order", "commerce_checkout" ],
    "ON" : [ "commerce_checkout_complete" ],
    "IF" : [
      { "commerce_payment_order_balance_comparison" : { "commerce_order" : [ "commerce_order" ], "value" : "0" } }
    ],
    "DO" : [
      { "commerce_order_update_status" : { "commerce_order" : [ "commerce_order" ], "order_status" : "completed" } }
    ]
  }
}

In short as soon as the balance is 0 I want the order to be complete.

2
  • You may want to try setting all of the paramaters. It doesn't say if they're required or not, but this could be the issue. Try doing this in Devel first. Install the devel module and go to yoursite.com/devel/php to run test code. commerce_order_status_update($order, $name, $skip_save = FALSE, $revision = NULL, $log = '') drupalcontrib.org/api/drupal/… – CR47 Nov 1 '13 at 16:03
  • If the above works by running it in devel's php page then something is conflicting with your function call, which may be a rule or the function is not getting called at all. You could also try runnig dpm($order) in that function, before, or after it, to print out the order object and see if it's being updated when it's supposed to. – CR47 Nov 1 '13 at 16:06
0

If the problem is simply that orders are being marked "paid in full" while still in checkout and then having their statuses overridden when the checkout completion rules run, why don't you just add a condition to the default checkout completion rules to not change the order status if it's already completed?

0

In the end I created a new rule:

{ "rules_complete_order" : {
    "LABEL" : "Complete Order",
    "PLUGIN" : "reaction rule",
    "TAGS" : [ "Commerce Checkout" ],
    "REQUIRES" : [ "commerce_payment", "commerce_order", "entity" ],
    "ON" : [ "commerce_payment_transaction_insert" ],
    "IF" : [
      { "commerce_payment_order_balance_comparison" : {
          "commerce_order" : [ "commerce-payment-transaction:order" ],
          "value" : "0"
        }
      }
    ],
    "DO" : [
      { "commerce_order_update_status" : {
          "commerce_order" : [ "commerce-payment-transaction:order" ],
          "order_status" : "completed"
        }
      }
    ]
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.