• Development

    Maintaining Lightbox2 Templating

    Lightbox2 is a very popular and powerful Drupal module. One of the helpful features is that you can render a Drupal node in a lightbox rather easily in either PHP or HTML. View detailed explanation. The issue is that when you click a link within that lightboxed content, you will lose the lightbox2 templating (e.g., if your lightbox template hides sidebars, they’ll only be hidden when the node loads. If you click a link within the lightbox, the new node will load and sidebars will appear). Read on for a quick fix.

  • Development

    Drupal 7 – Commerce Migration Class

    Here’s a migration class I’ve been working on to import 8200 products. The biggest feature of this code is that it will automatically create a single product display node that groups all products who share the same “grouping identifier.” So, in my CSV import file I have a “grouping_identifier” column. If a product is available in ten colors, and they all share the same grouping identifier, a single product display will be created and each of these products will be referenced in it. This will result in a product on the frontend that allows ten different color choices. I don’t have the time right now to explain anything more… please leave a comment if you have a question.

  • Development

    Google Docs Website Uptime Monitor

    A few months ago a colleague pointed me to a few blogs that were sharing Google Docs spreadsheets that offered free uptime monitoring for websites. Here are the original links that I checked out:

    The original spreadsheet (first link above) allowed single-site uptime monitoring. The spreadsheet would email you at a specified interval (every 5 minutes, for example) if the status of the website changed. Another developer made some enhancements to allow monitoring of multiple sites and also to offer SMS reminders. I decided it’d be fun to improve the usability of the spreadsheet, so my version:

  • Development

    Quick Tip: Adding a Reset button to a Drupal form

    Using hook_form_alter or hook_form_FORM_ID_alter one can easily add a “Reset” button to a Drupal form.

    In this example we’re actually trying to reset anything the user typed after the form loaded. This will not remove the default values.

    Here’s a simple example (Drupal 6)

    It may not be appropriate for you to put your new reset element into the buttons array. Use dpm() (part of the Devel module) to show what $form looks like. If you don’t understand this, and the code above isn’t working for you, you may try $form[‘reset_button’] = array….

    Adjust the value of #weight to move the button around the form. dpm($form) will show you weights (if any) of existing elements so you can make educated decisions about the weight of your new field.

    One last note about the ‘#type’ => ‘markup’ line: this is not a requirement, but I like to include it for clarity.

    UPDATE:
    Here’s what the field might look like for Drupal 7:

  • Development

    Drupal Commerce Add To Cart Form Tweaks / Registration Improvements

    In this example I’m showing how to improve the Add to Cart button for Drupal Commerce products to show differently based on whether or not users have already purchased a product, or whether the product is already in their cart.

    I’m currently working on a site where users are registering for “programs,” which are synonymous with classes, courses, etc. I’m using the following modules (among others) in this example:

    • Drupal Commerce
    • Registration
    • Commerce Registration

    Please understand that when a user registers for a course, they are actually purchasing a product that has a referenced Registration entity.

  • Development

    Views Exposed Filter: Terms for current language only

    I’ve been working on a multilingual site that has a product finder. We have 3 exposed filters that allow a user to select an Activity, IP Category, or Industry. All of these filters are Taxonomy Term filters. Some of the terms throughout those vocabularies have a specific language set, and should only show when that language is active.

    The first step is to make sure the output (Views results) only shows products where the node language matches the current language. This is easy using the built in Node translation: Language = Current user’s language filter.

  • Development

    Creating a Link on a Product Display Node to Edit a Referenced Product

    Drupal Commerce is amazing. On a recent project I had the pleasure of working with it for the first time. I understood the link between products and product displays, but there were a few things that bothered me about the relationship. This example demonstrates a simple administrative UI modification to make it easier to edit a product display node’s referenced product. Notice I said product, not products. On this site, the requirement calls for a one-to-one relationship. Every product display will only have a single product. You’ll have to make modifications (to the block’s contextual filter (to support multiple arguments) and the PHP code (to pass back multiple product ids)) if you want to show multiple referenced products.

  • Development

    Disabling the “Read more” link if specific conditions are met

    Here’s a simple way to remove the Read more link at the module level (in Drupal 7). Sometimes this is preferred over doing it at the theme level (because maybe we don’t want the link to appear no matter what theme is being used).

  • Development

    Proximity by City or Zip Code in Drupal 6 with Location and Views

    The location module for Drupal 6 is a robust module. On most projects, it gives us 100 percent of what we need. Proximity searching based on zip code is built-in and fairly painless to setup. I’ve recently been tasked to also allow proximity searching based on City. As you might imagine, the request is very similar. Both methods require the use of latitude and longitude (decimals). The difference is that instead of querying the database for latitude and longitude based on zip code (it’s usually termed postal code in Views, Location, etc.), we’re asking for the coordinates of a city. You’ll find that many cities have multiple zip codes, each of which is a row in the location module’s zipcodes database table. In this example, I’m not giving a real honest attempt at solving this issue, but rather I just return the first coordinate that matches the city.

  • Development

    Webform for Campaign Monitor

    Webform is an amazing module. Thankfully, you can extend it to make it even more helpful. We’ve had a lot of clients that offer a “Join Our Mailing List” type of functionality on their sites. These forms are typically one or two fields (email and name, usually) and are for anonymous users. We use Campaign Monitor for most clients.

    There is a Campaign Monitor module, but I prefer the following method, for various reasons.