You are here

function commerce_license_commerce_order_update in Commerce License 7

Implements hook_commerce_order_update().

1 call to commerce_license_commerce_order_update()
commerce_license_commerce_order_insert in ./commerce_license.module
Implements hook_commerce_order_insert().

File

./commerce_license.module, line 441
Provides a framework for selling access to local or remote resources.

Code

function commerce_license_commerce_order_update($order) {
  $licenses = commerce_license_get_order_licenses($order);

  // The order was canceled, revoke all of its licenses.
  if (isset($order->original) && $order->status != $order->original->status && $order->status == 'canceled') {
    foreach ($licenses as $license) {
      $license
        ->revoke();
    }
  }

  // Make sure the license is assigned to the correct user.
  foreach ($licenses as $license) {
    if ($license->uid != $order->uid) {
      $license->uid = $order->uid;
      entity_save('commerce_license', $license);
    }
  }
}