• 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

    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

    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

    States in key|value format

    The following is a list of the United States in key|value format. It’s useful when creating a select list in Drupal.

  • Development

    Countries in key|value format

    The following is a list of countries in key|value format. It’s useful when creating a select list in Drupal.