In our previous blog post about, the Social Microfunding website built in Drupal 7, we reviewed the high level goals of the project.  Here, we are going to dive deeper into the technology that we used for the website.

One of the goals of the ioby project was to allow people to fund projects by donating to one or more projects through the website.  For that piece of the application, we used the Drupal 7 Commerce module created by The Commerce Guys.  For those of you new to the Commerce Guys work, you may recognize them as the creators of the ever popular UberCart system, which is the most popular shopping cart system on Drupal6.

New Features using Drupal 7 and Commerce

There are a few key parts of the application that we built for ioby that hadn’t been tried using Drupal 7 or, more importantly, Drupal Commerce previously. Because the site is donation centric and we want supporters to be able to donate an arbitrary amount of money to one or more projects, the first challenge was to make a product to place in the cart that didn’t have a set price associated with it. In order to do this, we create the product ‘on the fly’ as the donation is placed into the cart.  The second challenge was to create a system that allows a user to also give a 20% gratuity directly to ioby so they are able to use the entirety of the donation to the project. The third challenge was  to give the ability for corporations and sponsors to match the donation amount as part of a campaign for matching funds for a project.

The first challenge was handled by using a simple form that allows the user to enter the amount of the donation they want to give to a project. This form submit creates a new commerce product using the Entity API system. The product was created and customized with the donation amount, and then placed into the cart. Each product in the Commerce module requires a unique SKU, so we generate one based on the users name, the project title, and a date reference to assure no products are duplicated. Once created, the product is placed into the users cart, and the user is redirected to the cart page.  One thing we uncovered is that the Commerce module is designed to set up the prices as an integer, instead of a decimal. This requires all prices to be converted back when placing data in or out of the database.  This had us stumped for a little while, and fortunately the developers of the Commerce module were kind enough to assist us in the implementation of updates to resolve this issue.

For the second challenge, gratuity was at first going to be a tax type in the Commerce system.  However, one of the requirements was to also give the user the ability to remove the gratuity if they felt that they didn’t want to cover the costs for it. Since tax isnt usually an optional item in shopping carts, the ability to remove it has not been placed in the Commerce tax module.  To enable that ability, we place the gratuity into a line item that is calculated every time the cart is updated. Once again we used the Entity API to generate a new product, and this time the gratuity type that has an individual SKU, and a price that is a percentage of the order total. Another custom feature we added was to show a popup message when a user removes the gratuity, explaining to them the importance of gratuity for ioby.  Since the view doesn’t discriminate between the different line items, it was necessary to use some front end javascript that handles this feature.  And of course, with items being added and removed from the cart, it was necessary to change the price of the gratuity on the fly, assuming it wasn’t removed.

For the third challenge – giving corporations and sponsors the ability to match the donation amount – we couldn’t just add line items to the donation like how user submitted donations are handled as this would change the donor information.  Instead, we had to add a new panel to the checkout process that let the donator know that the sponsor was helping the cause as well. The sponsor was tied to the project by campaign node and using the new Drupal7 database API to make direct calls to the database and tie the sponsor, campaign, project and donation together. The beauty of the new database API is that it allows the developer to tie together a series of statements together to create a complex SQL statement, making maintenance and updates easier. Once the bond is created, a donation match is created and funds attributed to the project, without charging the donator more.

This was a challenging and fun project for us.  New Signature was lucky to get to work directly with The Commerce Guys on some of the deep elements of the site, and their team was very accommodating with their support.  We were able to launch this  site on an accelerated time line, in conjunction with Earth Day 2011.