Kind of on topic... I was

Posts: 4
Joined: 11/21/2007

Kind of on topic...

I was tinkering with turning products into events for a side-project a while ago; all you have to do is create a new product class and add a date field to it with cck (the drupal event module at http://drupal.org/project/event/ works as well but I have events on non-consecutive days which it doesn't do).

To hide the add to cart button on events that are in the past you create an override in your template.php file.

The following override loops through the date field (which is required and can have multiple values) to find the maximum value and if it is in the past it hides the add to cart form. The product class I created is called 'workshop' and cck field I added to the node is called field_date.

function phptemplate_uc_product_add_to_cart($node) {
  if ($node->type == 'workshop') {
    $max_date = 0;

    // get max date
    foreach ($node->field_dates as $current_date) {
      $t = $current_date['value2'] ? $current_date['value2'] : $current_date['value1']; // use the to date if it exists
      if ($t > $max_date) $max_date = $t;
    }

    if ($max_date <= time()) {
      return false; // output blank
    }
  }

  // output add to cart form
  $output = '<div class="add_to_cart">';
  if ($node->nid) {
    $output .= drupal_get_form('uc_product_add_to_cart_form_'. $node->nid, $node);
  }
  else {
    $output .= drupal_get_form('uc_product_add_to_cart_form', $node);
  }
  $output .= '</div>';
  return $output;
}

Event registration integration By: ldutson (44 replies) Mon, 11/05/2007 - 11:48