You are here

function course_uc_enrol_user_in_ordered_courses in Course 6

Loops through items in an Ubercart order and enrols the user in courses purchased.

2 string references to 'course_uc_enrol_user_in_ordered_courses'
course_uc_ca_action in modules/course_uc/course_uc.module
Implements hook_ca_action().
course_uc_ca_predicate in modules/course_uc/course_uc.module
Implements hook_ca_predicate().

File

modules/course_uc/course_uc.module, line 251

Code

function course_uc_enrol_user_in_ordered_courses($order) {
  foreach ($order->products as $product) {
    $node = node_load($product->nid);
    $user = user_load($order->uid);
    if (course_node_is_course($node)) {

      // This product is an actual course. They have to be enrolled.
      // This will also satisfy the first payment requirement.
      // @see course_uc_course_enrol()
      course_enrol($node, $user, 'ubercart');
    }
    if ($courseNode = course_determine_context('course_uc', 'payment', $node->nid)) {

      // This product is also a course object, other than the first one.
      // Satisfy it!
      $course = course_get_course($courseNode, $user);
      foreach ($course
        ->getObjects() as $idx => $courseObject) {
        if ($idx != 0 && $courseObject
          ->getComponent() == 'payment' && $courseObject
          ->getInstanceId() == $node->nid) {

          // Found the course object that matched the instance (product).
          $courseObject
            ->getFulfillment()
            ->setComplete(TRUE)
            ->save();
        }
      }
    }
  }
}