You are here

function course_uc_init in Course 7

Same name and namespace in other branches
  1. 8.3 modules/course_uc/course_uc.module \course_uc_init()
  2. 8.2 modules/course_uc/course_uc.module \course_uc_init()
  3. 6 modules/course_uc/course_uc.module \course_uc_init()
  4. 7.2 modules/course_uc/course_uc.module \course_uc_init()
  5. 3.x modules/course_uc/course_uc.module \course_uc_init()

Implements hook_init().

File

modules/course_uc/course_uc.module, line 170

Code

function course_uc_init() {
  if (arg(1) == 'checkout') {
    global $conf;

    // Turn off content profile on registration for ubercart account creations.
    $conf['content_profile_profile']['registration_use'] = 0;
  }
  global $user;
  $cart = uc_cart_get_contents();
  foreach ($cart as $node) {
    if (course_node_is_course($node)) {
      $results = course_enroll_access($node, $user, FALSE, TRUE);
      if (count($results) > 1) {

        // There's always going to be one blocker, the purchase blocker.
        unset($results['course_must_purchase']);
        $result = reset($results);
        db_query("DELETE FROM {uc_cart_products} WHERE nid = :nid and cart_id = :uid", array(
          ':nid' => $node->nid,
          ':uid' => $user->uid,
        ));
        uc_cart_get_contents(NULL, 'rebuild');
        drupal_set_message(t('The activity "!title" was removed from your cart. !message', array(
          '!title' => l($node->title, "node/{$node->nid}"),
          '!message' => $result['message'],
        )), 'warning');
      }
    }
  }
}