Last Ubercart Alpha Version Reached

After a fine wrestling match in the office with CVS, tags, and project releases on d.o, I finally got the initial Alpha 8 release of Ubercart out the door. The last few alpha versions have seen marathons of development and feature additions, and this "minor" release is no different. Thanks in large part to Shawn and Lyle on the Ubercart team, we now have core functionality for file downloads and expirable role promotions (depending on a customer's purchases) and a good base of Workflow-ng integration providing administrators with a UI to create custom order workflows.

The two most requested features from folks I met at Drupalcon were related to the selling of digital goods and user account roles, and Shawn was able to use work that had already been contributed by third party developers (aymerick, CpILL, torgosPizza, and others) as a starting point for some really great module additions to the Ubercore. No time for a complete feature list here, and really no space either. Both modules are packed with excellent functionality, and we're already seeing a very positive response.

Warner Brothers Records has launched their first artist site using Ubercart selling Avenged Sevenfold fan club memberships with the new roles module and Workflow-ng support. Furthermore, the soon to be released redesign of Mike Nelson's RiffTrax will use Ubercart to sell downloads of the trax through a sharp looking custom catalog. The feedback and contributions from both these companies has been very helpful as we've implemented the new features.

So... all that combines together to make this one of the most exciting Ubercart releases to date. What's even better is this will be our last alpha version. We usually hit the minor versions pretty quick with install and update function fixes, but there will be no moving to Alpha 9. From here, we'll head to beta and beyond. Once we hit the 1.0 milestone, we'll set to work frantically updating Ubercart for Drupal 6 and finally get to a point where we can start using this for our own company's sites!

For those interested in demoing some of these new features, you can check out the recently revamped Ubercart Livetest. The site is running the latest code and demos a lot of the key features of Ubercart. (This product, for example, demos the file download system integrated with the product attribute system to sell music either as a CD or mp3 download.) Granted, I'm particularly proud of what goes on "under the hood" in the administrative menus and forms, but I'm also happy with the way the front end is working out. As elv pointed out indirectly through a post at g.d.o/usability, the user experience is very important, and we're working to make the customer user experience better with each new release.

So... feel free to check it out and post any bugs or suggestions in the appropriate forum, and while you're there, you may as well start dreaming of all the ways you can use Ubercart in your future projects. Wink

(Click here to view the news post at Ubercart.org. If this sounds like cool software to you, please vote for Ubercart at Intel's Cool Software site. We're not doing so bad in the rankings. 8))

Checking if a Drupal User has a Role

UPDATE: Over five years later, this post is still one of the most highly trafficked on my blog. Since then I've learned a lot and shared many other tips and modules. This past year I was honored to be a contributor to The Definitive Guide to Drupal 7, which includes many other great tips like this. I highly recommend it if you want to get the latest and greatest information on developing for Drupal.

I'm a little curious why a simple function to check if a user has a role doesn't exist in Drupal yet. Such curiosity that makes me wonder if I've just managed to miss it as long as I've been working with Drupal, so someone feel free to enlighten me. If anyone is looking for the same, please read on...

A fairly common task for me when adding PHP to CCK fields, Views arguments, content templates, etc. is to check whether the current user has been assigned a certain role. Generally in module development you're dealing with permissions and use user_access(), but when you're just customizing a site you often need such role based logic. (Drupal core has some, like the access settings for blocks.)

Use the following simple snippet to check if a user (in this example, it's the logged in user since I'm getting the global $user) has been assigned a certain role on your site:

<?php
 
global $user;

 
// Check to see if $user has the administrator role.
 
if (in_array('administrator', array_values($user->roles))) {
   
// Do something.
 
}
?>

Replace 'administrator' with whatever role it is you're trying to check against. Alternatively, if you keep a helper module for use on your projects, go ahead and drop this function in it:

<?php
/**
 * Check to see if a user has been assigned a certain role.
 *
 * @param $role
 *   The name of the role you're trying to find.
 * @param $user
 *   The user object for the user you're checking; defaults to the current user.
 * @return
 *   TRUE if the user object has the role, FALSE if it does not.
 */
function user_has_role($role, $user = NULL) {
  if (
$user == NULL) {
    global
$user;
  }

  if (
is_array($user->roles) && in_array($role, array_values($user->roles))) {
    return
TRUE;
  }

  return
FALSE;
}
?>

Please let me know if I put a typo up here or you know of an existing or easier way to do this!

New module idea... User Favorites

I've spent a couple hours today beginning to rebuild a website that I intended to offer up as a community activity tracking tool for the open source BASIC derivative language called FreeBASIC called the FB Tracker. Notes about the language itself (which rocks) aside, the site would be a fairly basic matter of allowing users to post and track projects, tutorials, snippets, sites, etc. through a single source. Most of this can be accomplished through some skillful use of Views + CCK, but there are a few community features I'll most likely be writing a module to implement. I have dubbed the module User Favorites and will post a few of my brainstorm ideas below...

I searched for a module similar to what I'm looking for and only found the Favorites module which is a far cry from what I need. The User Favorites module will actually allow users on a site to add content to a favorites list. It makes sense to give users the option of creating multiple favorites lists and will be fairly trivial to implement. Any of these lists may be set to be private or public lists. Users on large community or directory websites will be able to tag and track content through the site itself using their in site favorites list as well as provide feedback to the community regarding the value of content on the site.

Users will be able to browse the public favorites lists kept by other users as well as see who else on the site has favorited a specific piece of content. Favorites lists will be broken down by content type and sorted alphabetically, with users having the option to star a specific piece of content to make it sticky at the top of a list. Integration with Views means site developers will easily be able to create and sort lists of nodes ranked by how many times they've been favorited and/or starred. (Perhaps for the purposes of ranking, favorited content should count as 1 point while starred content should count as 3. Or rather... I can simply make that an administrative decision.) Integration with Userpoints means you can give users some love for providing feedback to other members of the community.

I'm happy to consider any further integrations with this module and am quite excited at the prospect of it being a first of its kind. However, if someone else knows of a module that may do something similar, please post it up here so I don't needlessly duplicate someone else's effort.

EDIT: A Tuesday morning, it's no longer past midnight, idea struck me on the way to work... I forgot to mention the idea of favoriting other users. This would allow you to track content posted by others and allow a ranking system for users similar to the one I mentioned above for content. It could be fun to use these statistics to display user relationships, user favorites compatibility (how much of your favorites match?), and other things like that. Maybe I can get Balazs to draw me up a user relationship graphic with his Drawing API. Lol

EDIT 2: Several folks have been posting up some very helpful pointers to modules that implement different parts of this idea. Let's just say... I'm never going to start a new module without doing a post like this first. This has been an invaluable learning experience, and hopefully I'll find some time to review the various modules and build on someone else's foundation.

Why use Drupal for e-commerce?

I recently posted a page to Ubercart.org titled, Why use Drupal for e-commerce?. In it I made some observations about Drupal and how it is the perfect platform on which to base an e-commerce site. All the things we wish other e-commerce specific systems would do (or that we have to hack to get done) Drupal does out of the box. Feel free to give it a read and offer up any feedback here.

A brief summary of my reasons include:

  • It's got great search engine optimization (including easy SEF URLs with the path and pathauto modules).
  • It's nice and secure with an active security team. (I've even got an e-mail in the past with someone from the team pointing out a hole in my code who had never even used the module! Kudos to the security team at Drupal.org!)
  • It's a very powerful content management system, which is a must for future e-commerce sites and a great benefit to companies that market products supported by a niche market or particular community.
  • There are many folks out there (like me!) who are available to help and to work for you as you start to setup your Drupal + Ubercart site. Having the whole directory of contributed modules and themes is great.

Anyways, enough shameless promotion of Drupal and Ubercart for now. I'm just about to roll out the Alpha 7d release and need to do one final test on an update from a previous version to make sure I don't go breaking anyone's site with the release!

Pages