You are here

function commerce_file_license_issue_by_commerce_order in Commerce File 7

Issue licenses for files in an order

1 call to commerce_file_license_issue_by_commerce_order()
commerce_file_rules_action_issue_order_licenses in ./commerce_file.rules.inc
Rules action: Grant file licenses for order owner based on a line item

File

includes/commerce_file.entities.inc, line 875
Handles file licenses and file license logs

Code

function commerce_file_license_issue_by_commerce_order($order, $updated_license_status = 'pending', $product_refresh = FALSE) {
  $updated_count = 0;

  // kick anonymous
  if (empty($order->uid)) {
    return $updated_count;
  }
  $account = user_load($order->uid);
  if (empty($account->uid)) {
    return $updated_count;
  }

  // wrap order and check for any line items
  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
  if (empty($order_wrapper->commerce_line_items)) {
    return $updated_count;
  }

  // issue licenses for each line item
  foreach ($order_wrapper->commerce_line_items as $delta => $line_item_wrapper) {
    $updated_count += commerce_file_license_issue_by_commerce_line_item($line_item_wrapper
      ->value(), $updated_license_status, $product_refresh, $order);
  }
  return $updated_count;
}