You are here

function commerce_registration_add_author_uid in Commerce Registration 7.2

Action callback

Adds a uid as the author_uid on a registration.

Related topics

File

./commerce_registration.rules.inc, line 240
Commerce Registration rules file.

Code

function commerce_registration_add_author_uid($order) {

  // Get all registrations that are from this order id and have 0 for the author_id
  // and do not have an anon_mail set. This indicates that they selected "myself" as
  // the person the registration is for so they did not have the opportunity to set the anon_mail field value.
  $regs = db_select('registration', 'r')
    ->fields('r')
    ->condition('order_id', $order->order_id)
    ->condition('author_uid', 0)
    ->execute();

  // Set the author_uid to the uid on the order for the orders registrations.
  foreach ($regs as $row) {
    $registration = registration_load($row->registration_id);
    $registration->author_uid = $order->uid;

    // If the order's email is the same as this registration's email then associate the user to this registration.
    if ($registration->anon_mail == $order->mail) {
      $registration->user_uid = $order->uid;
    }
    registration_save($registration);
  }
}