You are here

function course_uc_uc_add_to_cart in Course 3.x

Same name and namespace in other branches
  1. 8.3 modules/course_uc/course_uc.module \course_uc_uc_add_to_cart()
  2. 8.2 modules/course_uc/course_uc.module \course_uc_uc_add_to_cart()
  3. 7.2 modules/course_uc/course_uc.module \course_uc_uc_add_to_cart()
  4. 7 modules/course_uc/course_uc.module \course_uc_uc_add_to_cart()

Implements hook_add_to_cart().

File

modules/course_uc/course_uc.module, line 237

Code

function course_uc_uc_add_to_cart($nid, $qty, $data) {
  if (Drupal::config('course_uc.settings')
    ->get('restrict_qty', 1)) {
    $user = Drupal::currentUser();
    $node = Node::load($nid);
    if (course_node_is_course($node)) {
      if (course_uc_check_purchased($user, $node, $data)) {
        return array(
          array(
            'success' => FALSE,
            'message' => t('You have already purchased this course.'),
            'silent' => FALSE,
          ),
        );
      }
      if (course_uc_check_cart($node, $user, $data)) {
        $link = Link::createFromRoute(t('shopping cart'), 'uc_cart.cart');
        return array(
          array(
            'success' => FALSE,
            'message' => t('This course is already in your @cart.', array(
              '@cart' => $link
                ->toString(),
            )),
            'silent' => FALSE,
          ),
        );
      }
    }
  }
}