--- uc_node_checkout.module	2009-01-31 03:59:04.000000000 +1100
+++ uc_node_checkout.module	2009-04-06 15:32:28.000000000 +1000
@@ -90,7 +90,13 @@ function uc_node_checkout_admin_settings
  * Implementation of hook_perm().
  */
 function uc_node_checkout_perm() {
-  return array('administer node checkout');
+  $perms = array();
+  $perms[] = 'administer node checkout';
+  $types = node_get_types();
+  foreach ($types as $type) {
+    $perms[] = 'exempt from paying for '. $type->type;
+  }
+  return $perms;
 }
 
 /**
@@ -187,211 +193,214 @@ function uc_node_checkout_user($op, &$ed
  * Implementation of hook_form_alter().
  */
 function uc_node_checkout_form_alter(&$form, &$form_state, $form_id) {
-  global $user;
-
-  // Alters the product add to cart forms to redirect to the appropriate node
-  // add form if enabled.
-  if (variable_get('uc_node_checkout_add_to_cart_node_form', TRUE) &&
-      (strpos($form_id, 'add_to_cart_form') > 0 || strpos($form_id, 'uc_catalog_buy_it_now_form_') === 0)) {
-    // If a node type association exists for this product...
-    if ($type = uc_node_checkout_node_type_association($form['nid']['#value'])) {
-      // Store the node type in the form.
-      $form['node_type'] = array(
-        '#type' => 'hidden',
-        '#value' => $type,
-      );
-
-      // Change the submit handler to use the add to cart redirect handler.
-      $form['submit']['#submit'] = array('uc_node_checkout_add_to_cart_submit');
-    }
-  }
-
-  // Alter the cart view form to change node checkout product titles into edit
-  // links for the nodes they reference.
-  if ($form_id == 'uc_cart_view_form') {
-    $items = uc_cart_get_contents();
-    $i = 0;
-    foreach ($items as $item) {
-      if (isset($item->checkout_node)) {
-        $node = $item->checkout_node;
-
-        // Update the title if the based on user access.
-        if (variable_get('uc_node_checkout_cart_titles', TRUE)) {
-          if (node_access('update', $node)) {
-            $title = l($item->title, 'node/'. $node->nid .'/edit', array('query' => 'destination=cart'));
-
-            // Add the click to edit link to the title if necessary.
-            if (variable_get('uc_node_checkout_click_to_edit', TRUE)) {
-              $title .= ' '. theme('uc_cart_click_to_edit');
+  // skip everything if the user has permission to bypass this node type
+  if (!user_access('exempt from paying for '. $form['type']['#value'])) {
+    global $user;
+  
+    // Alters the product add to cart forms to redirect to the appropriate node
+    // add form if enabled.
+    if (variable_get('uc_node_checkout_add_to_cart_node_form', TRUE) &&
+        (strpos($form_id, 'add_to_cart_form') > 0 || strpos($form_id, 'uc_catalog_buy_it_now_form_') === 0)) {
+      // If a node type association exists for this product...
+      if ($type = uc_node_checkout_node_type_association($form['nid']['#value'])) {
+        // Store the node type in the form.
+        $form['node_type'] = array(
+          '#type' => 'hidden',
+          '#value' => $type,
+        );
+  
+        // Change the submit handler to use the add to cart redirect handler.
+        $form['submit']['#submit'] = array('uc_node_checkout_add_to_cart_submit');
+      }
+    }
+  
+    // Alter the cart view form to change node checkout product titles into edit
+    // links for the nodes they reference.
+    if ($form_id == 'uc_cart_view_form') {
+      $items = uc_cart_get_contents();
+      $i = 0;
+      foreach ($items as $item) {
+        if (isset($item->checkout_node)) {
+          $node = $item->checkout_node;
+  
+          // Update the title if the based on user access.
+          if (variable_get('uc_node_checkout_cart_titles', TRUE)) {
+            if (node_access('update', $node)) {
+              $title = l($item->title, 'node/'. $node->nid .'/edit', array('query' => 'destination=cart'));
+  
+              // Add the click to edit link to the title if necessary.
+              if (variable_get('uc_node_checkout_click_to_edit', TRUE)) {
+                $title .= ' '. theme('uc_cart_click_to_edit');
+              }
             }
+            else {
+              $title = check_plain($item->title);
+            }
+  
+            $form['items'][$i]['title']['#value'] = $title;
           }
-          else {
-            $title = check_plain($item->title);
-          }
-
-          $form['items'][$i]['title']['#value'] = $title;
-        }
-
-        // Add the node cart teaser beneath the title if necessary.
-        if (variable_get('uc_node_cart_teaser', TRUE)) {
-          if (variable_get('uc_node_order_product_teaser_override', FALSE)) {
-            $list = array(
-              token_replace(variable_get('uc_node_order_product_attribute', 'ID'), 'node', $node) .': '
-            . token_replace(variable_get('uc_node_order_product_option', '[nid] - [title]'), 'node', $node),
-            );
-            $teaser = theme('item_list', $list, NULL, 'ul', array('class' => 'uc-node-cart-teaser'));
+  
+          // Add the node cart teaser beneath the title if necessary.
+          if (variable_get('uc_node_cart_teaser', TRUE)) {
+            if (variable_get('uc_node_order_product_teaser_override', FALSE)) {
+              $list = array(
+                token_replace(variable_get('uc_node_order_product_attribute', 'ID'), 'node', $node) .': '
+              . token_replace(variable_get('uc_node_order_product_option', '[nid] - [title]'), 'node', $node),
+              );
+              $teaser = theme('item_list', $list, NULL, 'ul', array('class' => 'uc-node-cart-teaser'));
+            }
+            else {
+              $teaser = theme('uc_node_cart_teaser', $node);
+            }
+  
+            $form['items'][$i]['description']['#value'] .= $teaser;
           }
-          else {
-            $teaser = theme('uc_node_cart_teaser', $node);
+  
+          // Rebuild the description from the title and options.
+          $form['items'][$i]['desc']['#value'] = $form['items'][$i]['title']['#value'] . $form['items'][$i]['description']['#value'];
+        }
+        $i++;
+      }
+  
+      // Add a submit handler to check for removed products.
+      $form['update']['#submit'][] = 'uc_node_checkout_cart_view_submit';
+      $form['#submit'][] = 'uc_node_checkout_cart_view_submit';
+    }
+  
+    // Check stock levels on the checkout form and prevent checkout if specified.
+    if ($form_id == 'uc_cart_checkout_form' && module_exists('uc_stock')) {
+      // Loop through the items in the cart.
+      foreach (uc_cart_get_contents() as $item) {
+        // If an item is governed by node checkout...
+        if (isset($item->checkout_node)) {
+          // Get the stock level for each model.
+          $stock = uc_stock_level($item->model);
+  
+          // If the product has no stock...
+          if ($stock !== FALSE && $stock <= 0) {
+            // And we've set this to prevent checkout for node checkout nodes...
+            if (variable_get('uc_node_stock_prevent_checkout', TRUE)) {
+              drupal_set_message(t('Due to stock levels, you may not complete the purchase of %title at this time. Please contact us for more information.', array('%title' => $item->title)), 'error');
+              drupal_goto('cart');
+            }
           }
-
-          $form['items'][$i]['description']['#value'] .= $teaser;
         }
-
-        // Rebuild the description from the title and options.
-        $form['items'][$i]['desc']['#value'] = $form['items'][$i]['title']['#value'] . $form['items'][$i]['description']['#value'];
       }
-      $i++;
     }
-
-    // Add a submit handler to check for removed products.
-    $form['update']['#submit'][] = 'uc_node_checkout_cart_view_submit';
-    $form['#submit'][] = 'uc_node_checkout_cart_view_submit';
-  }
-
-  // Check stock levels on the checkout form and prevent checkout if specified.
-  if ($form_id == 'uc_cart_checkout_form' && module_exists('uc_stock')) {
-    // Loop through the items in the cart.
-    foreach (uc_cart_get_contents() as $item) {
-      // If an item is governed by node checkout...
-      if (isset($item->checkout_node)) {
-        // Get the stock level for each model.
-        $stock = uc_stock_level($item->model);
-
-        // If the product has no stock...
-        if ($stock !== FALSE && $stock <= 0) {
-          // And we've set this to prevent checkout for node checkout nodes...
-          if (variable_get('uc_node_stock_prevent_checkout', TRUE)) {
-            drupal_set_message(t('Due to stock levels, you may not complete the purchase of %title at this time. Please contact us for more information.', array('%title' => $item->title)), 'error');
-            drupal_goto('cart');
+  
+    // Alter the node forms for UC Node Checkout governed node types.
+    foreach (uc_node_checkout_product_map() as $type => $value) {
+      if ($form_id == $type .'_node_form') {
+        // Determine the product nid that will be added to the cart when this
+        // node is created.  First look for a single product node association.
+        if ($value['nid'] && !$value['view']) {
+          $product_nid = $value['nid'];
+        }
+        elseif ($_GET['product_nid']) {
+          // Otherwise look in the $_GET array.
+          $product_nid = $_GET['product_nid'];
+        }
+        elseif (empty($form['nid']['#value'])) {
+          // If none was found, we must ask the user to specify one.
+          drupal_goto('ucnc-select/'. $type);
+        }
+  
+        // If enabled, add attributes form to the top of the node form if the node
+        // has not already been checked out.
+        if (module_exists('uc_attribute') && empty($form['#node']->uc_order_product_id)) {
+          // Load up any attribute elements for this node's form.
+          $attributes = _uc_attribute_alter_form(node_load($product_nid));
+  
+          // If we got a result...
+          if (!empty($attributes)) {
+            // Put them in a tidy fieldset.
+            $form['attributes'] = array(
+              '#type' => 'fieldset',
+              '#title' => t('Product specifications'),
+              '#description' => t('Please specify your preferences from these options. Some may affect the final price of your purchase.'),
+              '#weight' => -10,
+              '#tree' => TRUE,
+            );
+            $form['attributes'] += $attributes;
+  
+            // Set defaults based on a GET variable.
+            if (!empty($_GET['attr'])) {
+              foreach (explode('_', $_GET['attr']) as $attr) {
+                list($aid, $oid) = explode('-', $attr);
+                $form['attributes'][$aid]['#default_value'] = $oid;
+              }
+            }
+  
+            // Override with any defaults found in the cart products table.
+            if ($item = uc_node_checkout_load_cart_item($form['nid']['#value'])) {
+              // Set the attribute options to those in the database.
+              foreach ($item->data['attributes'] as $aid => $oid) {
+                $form['attributes'][$aid]['#default_value'] = $oid;
+              }
+            }
           }
         }
-      }
-    }
-  }
-
-  // Alter the node forms for UC Node Checkout governed node types.
-  foreach (uc_node_checkout_product_map() as $type => $value) {
-    if ($form_id == $type .'_node_form') {
-      // Determine the product nid that will be added to the cart when this
-      // node is created.  First look for a single product node association.
-      if ($value['nid'] && !$value['view']) {
-        $product_nid = $value['nid'];
-      }
-      elseif ($_GET['product_nid']) {
-        // Otherwise look in the $_GET array.
-        $product_nid = $_GET['product_nid'];
-      }
-      elseif (empty($form['nid']['#value'])) {
-        // If none was found, we must ask the user to specify one.
-        drupal_goto('ucnc-select/'. $type);
-      }
-
-      // If enabled, add attributes form to the top of the node form if the node
-      // has not already been checked out.
-      if (module_exists('uc_attribute') && empty($form['#node']->uc_order_product_id)) {
-        // Load up any attribute elements for this node's form.
-        $attributes = _uc_attribute_alter_form(node_load($product_nid));
-
-        // If we got a result...
-        if (!empty($attributes)) {
-          // Put them in a tidy fieldset.
-          $form['attributes'] = array(
-            '#type' => 'fieldset',
-            '#title' => t('Product specifications'),
-            '#description' => t('Please specify your preferences from these options. Some may affect the final price of your purchase.'),
-            '#weight' => -10,
-            '#tree' => TRUE,
+  
+        // For node add forms...
+        if (empty($form['nid']['#value'])) {
+          $form['ucnc_product_nid'] = array(
+            '#type' => 'hidden',
+            '#value' => $product_nid,
           );
-          $form['attributes'] += $attributes;
-
-          // Set defaults based on a GET variable.
-          if (!empty($_GET['attr'])) {
-            foreach (explode('_', $_GET['attr']) as $attr) {
-              list($aid, $oid) = explode('-', $attr);
-              $form['attributes'][$aid]['#default_value'] = $oid;
-            }
+  
+          // If specified, redirect anonymous customers to login.
+          if (variable_get('uc_node_checkout_node_access', TRUE) && !$user->uid) {
+            drupal_set_message(t('You must login or create a user account to continue.'));
+            $_SESSION['node_checkout_redirect'] = 'node/add/'. str_replace('_', '-', $type);
+            drupal_goto('user');
           }
-
-          // Override with any defaults found in the cart products table.
-          if ($item = uc_node_checkout_load_cart_item($form['nid']['#value'])) {
-            // Set the attribute options to those in the database.
-            foreach ($item->data['attributes'] as $aid => $oid) {
-              $form['attributes'][$aid]['#default_value'] = $oid;
-            }
+          else {
+            unset($_SESSION['node_checkout_redirect']);
           }
-        }
-      }
-
-      // For node add forms...
-      if (empty($form['nid']['#value'])) {
-        $form['ucnc_product_nid'] = array(
-          '#type' => 'hidden',
-          '#value' => $product_nid,
-        );
-
-        // If specified, redirect anonymous customers to login.
-        if (variable_get('uc_node_checkout_node_access', TRUE) && !$user->uid) {
-          drupal_set_message(t('You must login or create a user account to continue.'));
-          $_SESSION['node_checkout_redirect'] = 'node/add/'. str_replace('_', '-', $type);
-          drupal_goto('user');
-        }
-        else {
-          unset($_SESSION['node_checkout_redirect']);
-        }
-
-        // If stock control is turned on, prevent adding an out of stock node.
-        if (module_exists('uc_stock')) {
-          $node = node_load($value['nid']);
-          $stock = uc_stock_level($node->model);
-
-          if ($stock !== FALSE && $stock <= 0) {
-            if (variable_get('uc_node_stock_prevent_add', FALSE)) {
-              drupal_set_message(t('Due to stock levels, this product is currently not available.'));
-              drupal_goto(variable_get('uc_node_stock_prevent_add_redirect', 'cart'));
-            }
-            elseif (variable_get('uc_node_stock_prevent_checkout', TRUE) && empty($form['#post'])) {
-              drupal_set_message(t('Due to stock levels, you will not be able to complete the purchase of this product. You may still create it and add it to your shopping cart until stock is available. Please contact us for more information.'));
+  
+          // If stock control is turned on, prevent adding an out of stock node.
+          if (module_exists('uc_stock')) {
+            $node = node_load($value['nid']);
+            $stock = uc_stock_level($node->model);
+  
+            if ($stock !== FALSE && $stock <= 0) {
+              if (variable_get('uc_node_stock_prevent_add', FALSE)) {
+                drupal_set_message(t('Due to stock levels, this product is currently not available.'));
+                drupal_goto(variable_get('uc_node_stock_prevent_add_redirect', 'cart'));
+              }
+              elseif (variable_get('uc_node_stock_prevent_checkout', TRUE) && empty($form['#post'])) {
+                drupal_set_message(t('Due to stock levels, you will not be able to complete the purchase of this product. You may still create it and add it to your shopping cart until stock is available. Please contact us for more information.'));
+              }
             }
           }
+  
+          // If enabled, alter the submit button to say "Add to cart".
+          if (variable_get('uc_node_checkout_alter_node_submit_button', TRUE)) {
+            $form['buttons']['submit']['#value'] = t('Add to cart');
+          }
         }
-
-        // If enabled, alter the submit button to say "Add to cart".
-        if (variable_get('uc_node_checkout_alter_node_submit_button', TRUE)) {
-          $form['buttons']['submit']['#value'] = t('Add to cart');
+  
+        // Remove restricted fields for users without access.
+        $fields = variable_get('uc_node_checkout_'. $type .'_restrictions', array());
+  
+        if (!empty($fields) && !user_access('edit any '. $type .' content')) {
+          foreach ($fields as $field) {
+            $form[$field]['#access'] = FALSE;
+          }
         }
-      }
-
-      // Remove restricted fields for users without access.
-      $fields = variable_get('uc_node_checkout_'. $type .'_restrictions', array());
-
-      if (!empty($fields) && !user_access('edit any '. $type .' content')) {
-        foreach ($fields as $field) {
-          $form[$field]['#access'] = FALSE;
+  
+        // Redirect non-administrators to the shopping cart after edits.
+        if (variable_get('uc_node_checkout_submit_redirect', TRUE) && !user_access('edit any '. $type .' content')) {
+          $form['#redirect'] = variable_get('uc_add_item_redirect', 'cart');
         }
       }
-
-      // Redirect non-administrators to the shopping cart after edits.
-      if (variable_get('uc_node_checkout_submit_redirect', TRUE) && !user_access('edit any '. $type .' content')) {
-        $form['#redirect'] = variable_get('uc_add_item_redirect', 'cart');
-      }
     }
-  }
-
-  // Redirect shopper back to node add form once they've logged in.
-  if (variable_get('uc_node_checkout_node_access', TRUE) && ($form_id == 'user_login' || $form_id == 'user_edit' || $form_id == 'user_register')) {
-    if (isset($_SESSION['node_checkout_redirect'])) {
-      $form['#redirect'] = $_SESSION['node_checkout_redirect'];
+  
+    // Redirect shopper back to node add form once they've logged in.
+    if (variable_get('uc_node_checkout_node_access', TRUE) && ($form_id == 'user_login' || $form_id == 'user_edit' || $form_id == 'user_register')) {
+      if (isset($_SESSION['node_checkout_redirect'])) {
+        $form['#redirect'] = $_SESSION['node_checkout_redirect'];
+      }
     }
   }
 }
@@ -507,114 +516,116 @@ function uc_node_checkout_product_select
  * Implementation of hook_nodeapi().
  */
 function uc_node_checkout_nodeapi(&$node, $op, $arg3 = NULL, $arg4 = NULL) {
-  switch ($op) {
-    // Add the associated product to the cart when a node is created that should
-    // be checked out.
-    case 'insert':
-      // If this node type is mapped to a product...
-      if (uc_node_checkout_node_associated($node)) {
-        // Load up the corresponding product so we can use the default add to
-        // cart quantity.
-        $product = node_load($node->ucnc_product_nid);
-
-        // Make sure we add at least 1 to the cart.
-        if (empty($product->default_qty)) {
-          $product->default_qty = 1;
-        }
-
-        // Build the preliminary add to cart data array.
-        $data = array('nid' => $product->nid, 'node_checkout_nid' => intval($node->nid));
-
-        // Setup the extra values that will be passed around.
-        $values = array(
-          'nid' => $product->nid,
-          'qty' => $product->default_qty,
-        );
-
-        // Add any attribute values if they exist.
-        if (isset($node->attributes)) {
-          $values['attributes'] = $node->attributes;
-        }
-
-        // Pass these values to modules for alteration.
-        $extra = module_invoke_all('add_to_cart_data', $values);
-
-        // Add to the add to cart data array based on the hook response.
-        foreach ($extra as $key => $value) {
-          if (!isset($data[$key])) {
-            $data[$key] = $value;
-          }
-        }
-
-        // Add the product to the cart!
-        uc_cart_add_item($product->nid, $product->default_qty, $data, NULL, FALSE, FALSE);
-      }
-      break;
-
-    // When a customer is updating a product in the cart with attributes, save
-    // any changed attribute options.
-    case 'update':
-      // Only save attributes if this node has not been checked out.
-      if (empty($node->uc_order_product_id)) {
-        $data = db_result(db_query("SELECT data FROM {uc_cart_products} WHERE data LIKE '%%\"node_checkout_nid\";i:%d;%%'", $node->nid));
-
-        $data = unserialize($data);
-        $data['attributes'] = $node->attributes;
-
-        db_query("UPDATE {uc_cart_products} SET data = '%s' WHERE data LIKE '%%\"node_checkout_nid\";i:%d;%%'", serialize($data), $node->nid);
-      }
-      break;
-
-    // Load any saved attributes output from the DB for display on the node.
-    case 'load':
-      $node->uc_order_product_id = db_result(db_query("SELECT order_product_id FROM {uc_node_checkout_order_products} WHERE nid = %d", $node->nid));
-      break;
-
-    // When enabled, deletes nodes from the site when their creators remove the
-    // associated products from their cart.
-    case 'delete':
-      // Skip this whole block of code if we're not supposed to delete orphans.
-      if (variable_get('uc_node_checkout_delete_orphans', TRUE)) {
+  if (!user_access('exempt from paying for '. $node->type)) {
+    switch ($op) {
+      // Add the associated product to the cart when a node is created that should
+      // be checked out.
+      case 'insert':
+        // If this node type is mapped to a product...
         if (uc_node_checkout_node_associated($node)) {
-          db_query("DELETE FROM {uc_cart_products} WHERE data LIKE '%%\"node_checkout_nid\";i:%d;%%'", $node->nid);
-          if (db_affected_rows()) {
-            // Display a message here if necessary.
+          // Load up the corresponding product so we can use the default add to
+          // cart quantity.
+          $product = node_load($node->ucnc_product_nid);
+  
+          // Make sure we add at least 1 to the cart.
+          if (empty($product->default_qty)) {
+            $product->default_qty = 1;
+          }
+  
+          // Build the preliminary add to cart data array.
+          $data = array('nid' => $product->nid, 'node_checkout_nid' => intval($node->nid));
+  
+          // Setup the extra values that will be passed around.
+          $values = array(
+            'nid' => $product->nid,
+            'qty' => $product->default_qty,
+          );
+  
+          // Add any attribute values if they exist.
+          if (isset($node->attributes)) {
+            $values['attributes'] = $node->attributes;
+          }
+  
+          // Pass these values to modules for alteration.
+          $extra = module_invoke_all('add_to_cart_data', $values);
+  
+          // Add to the add to cart data array based on the hook response.
+          foreach ($extra as $key => $value) {
+            if (!isset($data[$key])) {
+              $data[$key] = $value;
+            }
           }
+  
+          // Add the product to the cart!
+          uc_cart_add_item($product->nid, $product->default_qty, $data, NULL, FALSE, FALSE);
         }
-      }
-      db_query("DELETE FROM {uc_node_checkout_order_products} WHERE nid = %d", $node->nid);
-      break;
-
-    // When enabled, redirects users to their cart when they try to view a node
-    // governed by UC Node Checkout that hasn't been checked out yet.
-    case 'view':
-      // Skip this whole block of code if this setting isn't enabled.
-      if (variable_get('uc_node_checkout_view_redirect', TRUE) && $arg4 === TRUE) {
-        if (uc_node_checkout_node_associated($node) &&
-            !user_access('edit any '. $node->type .' content') &&
-            uc_node_checkout_load_cart_item($node->nid)) {
-          drupal_goto(variable_get('uc_add_item_redirect', 'cart'));
+        break;
+  
+      // When a customer is updating a product in the cart with attributes, save
+      // any changed attribute options.
+      case 'update':
+        // Only save attributes if this node has not been checked out.
+        if (empty($node->uc_order_product_id)) {
+          $data = db_result(db_query("SELECT data FROM {uc_cart_products} WHERE data LIKE '%%\"node_checkout_nid\";i:%d;%%'", $node->nid));
+  
+          $data = unserialize($data);
+          $data['attributes'] = $node->attributes;
+  
+          db_query("UPDATE {uc_cart_products} SET data = '%s' WHERE data LIKE '%%\"node_checkout_nid\";i:%d;%%'", serialize($data), $node->nid);
         }
-      }
-
-      // Add any existing attribute text to the node on a full pageview.
-      if ($arg4 === TRUE && !empty($node->uc_order_product_id)) {
-        drupal_add_css(drupal_get_path('module', 'uc_node_checkout') .'/uc_node_checkout.css');
-
-        // Load the product from the order.
-        $product = uc_node_checkout_load_order_product($node->uc_order_product_id);
-
-        // If it has attributes on it, set them to display.
-        if (is_array($product->data['attributes']) && count($product->data['attributes']) > 0) {
-          $node->content['uc_attribute_text'] = array(
-            '#data' => $product->data['attributes'],
-            '#value' => theme('uc_node_checkout_node_attributes', $product),
-            '#weight' => -10,
-          );
+        break;
+  
+      // Load any saved attributes output from the DB for display on the node.
+      case 'load':
+        $node->uc_order_product_id = db_result(db_query("SELECT order_product_id FROM {uc_node_checkout_order_products} WHERE nid = %d", $node->nid));
+        break;
+  
+      // When enabled, deletes nodes from the site when their creators remove the
+      // associated products from their cart.
+      case 'delete':
+        // Skip this whole block of code if we're not supposed to delete orphans.
+        if (variable_get('uc_node_checkout_delete_orphans', TRUE)) {
+          if (uc_node_checkout_node_associated($node)) {
+            db_query("DELETE FROM {uc_cart_products} WHERE data LIKE '%%\"node_checkout_nid\";i:%d;%%'", $node->nid);
+            if (db_affected_rows()) {
+              // Display a message here if necessary.
+            }
+          }
         }
-      }
-
-      break;
+        db_query("DELETE FROM {uc_node_checkout_order_products} WHERE nid = %d", $node->nid);
+        break;
+  
+      // When enabled, redirects users to their cart when they try to view a node
+      // governed by UC Node Checkout that hasn't been checked out yet.
+      case 'view':
+        // Skip this whole block of code if this setting isn't enabled.
+        if (variable_get('uc_node_checkout_view_redirect', TRUE) && $arg4 === TRUE) {
+          if (uc_node_checkout_node_associated($node) &&
+              !user_access('edit any '. $node->type .' content') &&
+              uc_node_checkout_load_cart_item($node->nid)) {
+            drupal_goto(variable_get('uc_add_item_redirect', 'cart'));
+          }
+        }
+  
+        // Add any existing attribute text to the node on a full pageview.
+        if ($arg4 === TRUE && !empty($node->uc_order_product_id)) {
+          drupal_add_css(drupal_get_path('module', 'uc_node_checkout') .'/uc_node_checkout.css');
+  
+          // Load the product from the order.
+          $product = uc_node_checkout_load_order_product($node->uc_order_product_id);
+  
+          // If it has attributes on it, set them to display.
+          if (is_array($product->data['attributes']) && count($product->data['attributes']) > 0) {
+            $node->content['uc_attribute_text'] = array(
+              '#data' => $product->data['attributes'],
+              '#value' => theme('uc_node_checkout_node_attributes', $product),
+              '#weight' => -10,
+            );
+          }
+        }
+  
+        break;
+    }
   }
 }
 
