## Blocks: Coupon

block_coupon
Maintained by Sebsoft Plugins, Rogier van Dongen
The Sebsoft Coupon Plugin offers you the possibility to create coupons for various levels of course access. Using a coupon code, users will be enrolled into courses that are attached to the coupon.
276 sites
52 fans

SEBSOFT COUPON PLUGIN

The Sebsoft Coupon Plugin offers you the possibility to create coupons for various levels

of course access. Using a coupon code, users will be enrolled into courses that are attached to the coupon. That way, you can use the coupon system as voucher or vouchering system for your course(s).

There are a few different ways of generating coupons:

- Course level: this means one or more course(s) need to be selected for which the coupon is valid.

Once the coupon code is entered by a user, he or she will be enroled in every course the coupon

is attached to.

A nice extra feature is, when groups are configured for a certain course, you can configure which

course group the coupon is for. When a user claims the coupon, he or she will be added to that specific

group in the course. This makes it possible to separate coupon users from regular users.

You could also make specific course groups every time you generate a batch of new coupons, so there's

some way of matching a batch of coupons to a group of users. The possibilities are numerous.

- Cohort level: this means one or more cohort(s) need to be selected for which the coupon is valid.

Once the coupon code is entered by a user, he or she will be added as a cohort member for every

cohort the coupon is attached to.

NOTE: When generating cohort level coupons, there is a possibility to "connect" extra courses to

a given cohort. One MUST know that upon doing this, the courses will at that point be added to

the cohort enrolment sync. Without knowing this little fact, it could be "unexpected" behavior,

even though it's a logical step.

Furthermore, coupons can be generated on two "access" levels:

- Personalized. The base of this, is either a CSV is uploaded, or a CSV is given directly in a textbox.

The needed user information for every coupon to be generated will be the user's name, email address

and gender.

These coupons will then be generated and sent off to the appropriate users using a background task.

- Bulk: The base of this is simple: you generate a certain amount of access coupons, which will then

be emailed to the pre-configured recipient or (if allowed) to an emailaddress that can be freely entered.

- WARNING:

Wherever possible, please use PNG images.

Also, whenever possible, do NOT use images that have an alpha channel.

This will MASSIVELY slow down processing time, due to internal conversion of images by TCPDF.

On our tests, for a 300 DPI image on A4 format (2480 x 3508 pixels) with an alpha channel,

rendering a single PDF took around 25 seconds. Taking the alpha channel out of the image,

rendering a single PDF was reduced to around 3 seconds.

Furthermore, whenever possible, have the coupon generator create a single PDF with all

coupons (this is only applicable when generating coupons in "bulk" mode). The process of

generating coupons has been optimized to only "use" the image 1 time when creating any amount

of coupons in a single PDF. If you choose the option to create a seperate PDF for every coupon,

the image will have to be rendered for each and every PDF.

This has 2 major downfalls:

1. Every PDF will roughly have a slightly bigger size than the image size (in our tests, 350 - 400 kB per PDF)

2. Every PDF takes the full amount of time to render.

Effectively, this means the following (using fictitious sizes):

10 coupons, single PDF -> result is around 400 kB, rendering takes around 3-4 seconds.

10 coupons, seperate PDFs -> result is around 4 MB, rendering takes around 35-40 seconds.

INSTALLATION INSTRUCTIONS

- Copy the coupon folder to your blocks directory.

- Go to the moodle admin pages (you will probably be confronted with it anyway) and install the plugin

- Configure the main settings for the plugin.

- We're set up for usage!

PLACEMENT OF THE PLUGIN

There are only two pages you can add the coupon block on. This is the site's frontpage

or the user dashboard (my) page. The main reason for this is because the block is the

"frontend" for users to enter their coupon or voucher code.

Administrators and users with the correct capabilities will also see the links to

the coupon administration pages and the coupon generator page.

GENERAL CONSIDERATIONS

There's two main configurations to consider when generating coupons.

For course type coupons, this plugin attempts to enrol a user through use of Moodle's

internal function "enrol_try_internal_enrol".

The Moodle documentation shows it will attempt to enrol you using manual enrolment.

For this reason manual enrolment MUST be enabled for these courses.

For cohort type coupons, a user is made a member of a cohort. That's all there is to it.

Surprise though, if you want to actually make a user have access to a course, you

probably want to configure cohort enrolment for the course.

For those paying attention, creating cohort type coupons thus enables a simple

way of enrolling users into multiple courses at once just by configuring the right

cohort enrolments in multiple courses.

That's still not to say course coupons can't be used in a similar way (using meta courses).

### Contributors

Rogier van Dongen

### Awards

• Wed, 8 Aug 2018, 3:28 AM
Hi, this looks like a great plugin. We have an online language school and we are looking at doing a trial class for students instead of enrolling onto a full course at full price. Do you think this plugin would work for offering 1 lesson? Otherwise I think I would need to enrol students manually onto the course.......
• Thu, 13 Sep 2018, 5:41 AM
Thank you so much, this plugin has worked perfectly and been such an asset! I'm wondering if you have given any consideration to making it so the plugin can be used to purchase coupon codes, so someone would be able to purchase lessons as gifts?
• Fri, 21 Sep 2018, 6:48 AM
Hello Rogier,

Can you tell me how to change the informations inside the coupon ? It seem that we can only change the image of the coupon, but what about the text ?

Thanks
• Mon, 24 Sep 2018, 3:32 PM
Hi Stephane,

Please check the language files for the information that's displayed inside the Coupon .
• Wed, 3 Oct 2018, 11:32 PM
I'm wondering if this plugin could be extended to using it with making a new account? So when a non-registrated user has a couponcode, at the moment that he want to register on the site an extra field is shown for a couponcode, and after registration with a valid code the user is automatically placed in a site- and coursegroup.
• Wed, 3 Oct 2018, 11:37 PM
Hi Franky,
You mean like https://yourmoodle/blocks/coupon/view/signup.php? - (Do note, that to enforce this, you will have to use that page as signup page)
• Thu, 4 Oct 2018, 12:14 AM
Hi Sebastian,

yes, this is exactly what I mean. I've now only put the URL in, and then indeed a field couponcode is showing up at the top. I've not tested it yet further if this works correctly. Is there in the backend a field where you can fill in this specific URL instead of the URL of the normal registration page? I didn't find this field so far.
• Thu, 4 Oct 2018, 12:40 AM
In backend there is a field to change the Login URL, but it seems that there is surprisingly not a field to change the Signup url. This would mean that this has to be changed in the CFG-file?
• Thu, 4 Oct 2018, 9:20 PM
Hi Franky,
Unfortunately, no. The one way we've been able to implement this without enforcing Moodle core hacks, is by using custom scripts.
To configure, do the following:
modify your Moodle config.php and add a line "$CFG->customscripts = /path/to/customscripts/" You will usually either out your customscripts either IN the moodle datadir, or just outside of the www-root, e.g.: /yourhomedir/moodledata/customscripts Now, add a folder called "login" so you end up with: /yourhomedir/moodledata/customscripts/login/ Finally, add a php file called signup.php, so you end up with: /yourhomedir/moodledata/customscripts/login/signup.php The ONLY thing you need to do here is enter a redirect statement so you end up with the coupon signup url: <?php // This script does nothing more than redirect to the coupon signup method. redirect($CFG->wwwroot . '/blocks/coupon/view/signup.php');
exit;

and that's it. Using these 4 lines of code, you're now set up to use the custom signup
Let me know if you get this to work.
Good luck & cheers,
Rogier
• Fri, 5 Oct 2018, 3:10 AM
Hi Rogier,

Thanks for your advice, this saved me some time to search this out myself. I've implemented your tip and the redirects works fine. Thanks again.

Franky
• Sat, 20 Oct 2018, 4:15 AM
Hello , im .new to moodle , i just installed your plugin but i can't find a way to generate coupons! i searched everywhere but. no sign of it except the config section. but no way to start generating coupons for courses ? any helo with screebshots if possible !
• Mon, 22 Oct 2018, 3:40 PM
Hello Qasmaoui, a first draft of a manual we're working on to get you started can be found on our repository pages.
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.3327648639678955, "perplexity": 2898.699432117372}, "config": {"markdown_headings": true, "markdown_code": false, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2018-47/segments/1542039741294.2/warc/CC-MAIN-20181113062240-20181113084240-00075.warc.gz"}