Moodle and e-commerce shopping carts

Linking Moodle to a web based shopping cart is easy and requires very little coding to allow users to browse courses, add them to a cart, pay for them, and then automatically gain access to the paid courses on Moodle.  And best if all, only use one login for the entire process.

Moodle + Magneto = Amazing Moodle Shopping CartMy personal favourite Open Source carts are OS Commerce and the newer, slicker Magento.  But it really doesn’t matter which cart you use, as long as it is driven by a popular web database such as MySQL or MSQL. It can be home grown or a commercial platform.

This short blog posts explains the process in its simplest terms.

In your online shop you create courses as products. You can put them in categories, offer discounts and name then whatever you like. Just like you would if we’re selling DVDs or shoes.

The important bit is to use a unique field for your product that we can use as a course ID number in Moodle.

Once you have your courses entered into your shop and you’ve configured it to accept payments and create accounts you are ready to instruct Moodle to read the products and the users from the shop database.

For this step we will be using 2 important Moodle features.

  1. Plugins > Authentication
  2. Plugin > Enrolment

Under the authentication plugin in Moodle, choose “External Database” and complete the form to match the credentials of your shopping carts database.  You will need to know the user fields used in your shopping cart and basically match them up to the user fields in Moodle.

Now under the enrolment plugin we need to do the same thing, this time we are matching fields from your product table with fields in the Moodle course table.

Now make sure that your courses have the same IDNUMBER as your products in the shopping site.  Lastly, make sure both plugins are enabled and away you go.

Here’s  a quick recap of the process and what happens:

  1. Your user visits your shopping site
  2. They browse for courses and add them to the cart
  3. They go to the checkout and pay for the courses and enter their personal details
  4. Now they can visit your Moodle site and login with the same details they just entered for the shopping site
  5. Moodle will log in the user and enrol them on the correct courses (i.e the ones they have paid for).

You can take this further and theme the shopping site to match your Moodle install and customise the emails to provide direct links to the course in the emailed receipt.  And if you want to go even further, you could tweak the code to keep the same login session so it’s seamless between the 2 systems.

I hope you found this useful and if anyone is thinking about creating a shopping cart for Moodle.

 

Block Building for Moodle 2

This year, instead of hacking the Moodle core to death we have decided to stick with core Moodle code, and this time we have put all our custom pages in their own folder.
I am in the process of converting many custom code projects into blocks and mods. An it’s surprisingly easy with Moodle 2.

Today I built a simple course header block that displays the course title with a nicely rounded CSS background image.
Previously we used to draw course headers in Photoshop but now we don’t need to.
And because we can place blocks in the centre of our theme the headers sit very neatly at the top of the course content above the resources.

At present it’s limited to 1 image but the plan is to develop it further whereby the tutor can select from a variety of images when in editing mode.
For example, there may be an image for construction courses, one for hairdressing courses etc… Plus a few generic ones.

This saves hours of time – no more Photoshop!

The next mod we need to build is similar to a label but instead creates a pre-drawn banner and associated link to a child course. At present we draw images, add them to a label and hyperlink them to a hidden child course. Painful and time consuming!

However, time is always the issue. And we are fully stretched with a new term just a few days away so finding time to code is harder than the code itself!
It will be non stop tech support for the next month and then we will see how we go!

And the senior powers that be require a Moodle reporting engine that links to our MIS system! I’d rather build the fun stuff but need to keep the bosses happy!

Bug fixing week (Moodle 2)

This week I finally found some time to sit in front of my computer and address some of the niggly little glitches that have arisen since our Moodle 2 upgrade.

One of which was the sending of emails via the cron. For some unknown reason, Moodle 2 could not initiate the send mail function. After several hours debugging and trying various things I decided to put the path to the sendmail server directly into Moodle, as opposed to using the default PHP path. And sure enough it worked! Even though the paths are exactly the same and worked prior to the upgrade, this was the only way I could get around it.

The next problem I had was with external Database enrolments via ODBC . For some reason, our Moodle 2.0 installation was refusing to run the queries even though I could communicate directly with the external database. Eventually, after searching through countless PHP pages I decided to drop ODBC in favour of FreeTDS. This worked like a charm.

Lastly, our cron was falling over when trying to run the course completion function. This was due to a mismatch in database collations. For some reason, 3 of our tables were set to utf8_general_ci, instead of utf_unicode_ci. I changed these tables to unicode and the cron completed this action.

Then I encountered another problem. Again cron related Playtech Casinos. The process kept on terminating whilst completing meta enrol enrolments. This happened everytime and just by chance I happened to time how long the process would last until it terminated. It was exactly 60 seconds. So to fix this I changed the timeout in php.ini to a much longer time limit of 300 seconds and now the cron completes perfectly.

It is now the end of the week and although the above fixes are more work arounds as opposed to actual core fixes at least things are working again. I have submitted some of my findings to the Moodle Tracker and hopefully some of these issues will be resolved in future releases.

I finished the week by installing the Drag and Drop file uplaoder block by the brilliant Davo Smith. This is by far my favourite block of all time. For those that are unfamiliar with it check out: http://moodle.org/mod/forum/discuss.php?d=181988

The only hack I had to make was to make the block sticky on all courses. As it’s a course block its not possible to make it sticky in Moodle 2.0 on all course pages by default.

To do this find the line:

function applicable_formats() {
return array('course' => true);
}

And change to:

function applicable_formats() {
return array('all' => true);
}

Now you can add the block to the frontpage and set it to appear on all pages.
Once my workload settles down I’m looking forward to coding and developing again.

My Moodle 2.0 Upgrade Journey Part 4 (Final)

Moodle 2.0 is now live at the Leeds City College!

It’s been a very busy week but we finally got there.  It’s by no means finished.  There are still lots of little tweaks needed throughout the summer but it’s working – which wasn’t an easy task.

After the upgrade I found that many of the links to resources were not working, even though the fields were correctly associated with them.  It turns out this has something to do with the description fields being empty and the priority ID order.  There’s plenty of discussion about this in the Moodle forums.

I managed to patch the early version of Moodle 2.0 with the latest release and it fixed the broken links problem.

The upgrade has however caused errors with the theme selector.  It appears as though I can only select one theme, not too much of an issue at this stage but something I will have to repair later.

The book module upgrade went well and I’ve decided to leave the Questionnaire Module out in favour of the new Feedback Module. Moodle folders doesn’t fully work yet as it’s not Moodle 2.0 ready but LDAP and Database Enrollments are fully restored and things look promising.

For the rest of the week I’ll be installing the various repositories and wait for our college tutors to come knocking at the door wondering why everything has changed.

 

 

 

My Moodle 2.0 Upgrade Journey Part 3

Well today I finally set about upgrading the Leeds City College Production Server and it has been quite an eventful day.

After making the necessary changes to Apache and PHP (namely upgrading them both) and then backing up a snapshot of the live system I began the upgrade.

Even though I have simulated this many times on a test server doing it live threw up problems I had not yet encountered.  The first error I got was an Illegal mix of collations, I don’t think was a reference to the current UK government but more a warning to me to stop mucking around with the tables.

I had to run a quick query against the tables in the database

ALTER TABLE mdl_tablename CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;

And this fixed things.

Then I hit my second error, “Debug info: Unknown column ‘itemid’ in ‘field list'”

Having absolutely no idea how to fix this I spent the next few hours in the forums/tracker and came out none the wiser.

I then decided to just opt for a clean install before moving on just to see if the error is more to do with my current setup.  It turns out the latest snapshot of Moodle 2.1 has a slight fault in it, whereby I can’t select any themes but it installed nevertheless.

I revisited the earlier error above and still couldn’t find a fix.  The Moodle developers have done a lot more work on the install script since I downloaded it several months ago and by chance I had still had an older version.

I deleted the current failed Moodle 2.0 from the server, restored the database and tried an install and to my delight this one works.

So currently it’s migrating all the course files and this will take several hours so this blog post will end here and pick up tomorrow.  The plan is to upgrade this old Moodle 2.0 with the new version.  I realize it’s a patchy way to work but I have no choice and time is running out as this project is due completion in 4 days from now.

And although I’m on my fifth cup of tea I’m still feeling quite calm.