enrol multiple courses as a whole after receiving payments

enrol multiple courses as a whole after receiving payments

by Peter Haasdijk -
Number of replies: 2

I have a Moodle configuration with a dozen courses. Students can buy eight of these courses as a whole. New students have to register themselves and, after paying the one amount, they get access to these eight courses.

I installed a payment plugin for the payments and i am now trying to reach my goal (enrol eight courses after receiving payment) through auto enrollment. However, with auto enrollment, access of students is linked to having an account and not having payed for the courses, so that doesn't work for me. And i doubt if making use of groups and synchronise courses in some way is a solution here. I have never used groups before so i'm definitely not sure about this.

Anyone knows what is the best way to solve this?

Peter

Average of ratings: -
In reply to Peter Haasdijk

Re: enrol multiple courses as a whole after receiving payments

by Renaat Debleu -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers
I would create an events and observer file in your theme:

db/events.php

$observers = array(
    array(
        'eventname' => '\core\event\user_enrolment_created',
        'callback'  => 'theme_????_observer::userenroled',
        'internal'  => false,
        'priority'  => 0,
    ),
);

classes/observer.php

class theme_???_observer {
    public static function userenroled(\core\event\user_enrolment_created $enrolment) {
        if (!empty($enrolment)) {
            if ($enrolment->courseid != 10) {
                enrol_try_internal_enrol($courseid1, $enrolment->relateduserid);
                enrol_try_internal_enrol($courseid2, $enrolment->relateduserid);
                ...
            }
        }
    }
}
In reply to Renaat Debleu

Re: enrol multiple courses as a whole after receiving payments

by Peter Haasdijk -

Hi Renaat,

Thank you very much for your suggestion. I will check this one for sure.

Peter