Getting Notice: Undefined property: stdClass::$course in course_uc_form_alter() (line 58 of /path/to/drupal/sites/all/modules/course/modules/course_uc/course_uc.module) and Notice: Undefined index: settings in course_uc_form_alter() (line 61 of /path/to/drupal/sites/all/modules/course/modules/course_uc/course_uc.module). Doesn't show after the user has purchased and filled out enrollment fields.

Comments

lardfw created an issue. See original summary.

modimanz’s picture

I am only getting the second message (line 61), not sure why node->course doesn't exist for you. You could try something similar to line 58, but this may be a symptom of a more serious problem.

Starting at Line 61: I added a check to see if the field was set. Good luck sir.

        if (isset($instance['settings']['course_enrollment_user_field'])) {
          if ($instance['settings']['course_enrollment_user_field']) {
            // At least one field must be shown when enrolling. Display the user
            // enrollment form.
            $enrollment->nid = $node->nid;
            $enrollment->uid = $user->uid;
            $enrollment->type = $node->course['enrollment_type'];
            $form['course_enrollment'] = array();
            $form['course_enrollment']['#tree'] = TRUE;
            $form['course_enrollment']['#parents'] = array('course_enrollment');
            field_attach_form('course_enrollment', $enrollment, $form['course_enrollment'], $form_state);
            $form['#submit'] = array(
              'uc_product_add_to_cart_form_submit',
              'course_uc_add_to_cart_form_submit',
            );
            break;
          }
        }
modimanz’s picture

It may be better to change line 61 to do an isset() instead of the initial if(field) then it wouldn't need both, but i haven't looked at the code enough yet to know any more than that I did not want that error. As far as I know the field could have a false state.

modimanz’s picture

This function seems to just be blocking the Add to Cart button when required so I don't think this will break anything.

If course is not loading into $node from course_node_load() hook then it is likely the node->nid is not found in the course_node table.

The code below resolves the errors, but again, I don't know the underlying cause.

function course_uc_form_alter
course_uc.module: line 57

    if ((!isset($form['actions']['submit']['#access']) || $form['actions']['submit']['#access']) && isset($node->course)) {
      $instances = field_info_instances('course_enrollment', $node->course['enrollment_type']);
      foreach ($instances as $field_name => $instance) {
        $field = field_info_field($field_name);
        if (isset($instance['settings']['course_enrollment_user_field'])) {
          if ($instance['settings']['course_enrollment_user_field']) {
            // At least one field must be shown when enrolling. Display the user
            // enrollment form.
            $enrollment = new stdClass();
            $enrollment->nid = $node->nid;
            $enrollment->uid = $user->uid;
            $enrollment->type = $node->course['enrollment_type'];
            $form['course_enrollment'] = array();
            $form['course_enrollment']['#tree'] = TRUE;
            $form['course_enrollment']['#parents'] = array('course_enrollment');
            field_attach_form('course_enrollment', $enrollment, $form['course_enrollment'], $form_state);
            $form['#submit'] = array(
              'uc_product_add_to_cart_form_submit',
              'course_uc_add_to_cart_form_submit',
            );
            break;
          }
        }
      }
    }
  }
modimanz’s picture

My problem was corruption in one of my course module files. Updating the modules files fixed my issues.

djdevin’s picture

Status: Active » Closed (cannot reproduce)

Good to hear :)

lu_smithcon’s picture

I did a clean install and am no longer getting the message either.