--- uc_custom_price-ORIG.module	2010-09-10 18:50:33.000000000 -0400
+++ uc_custom_price.module	2010-09-10 18:52:52.000000000 -0400
@@ -80,7 +80,7 @@ function uc_custom_price_form_alter(&$fo
   elseif (isset($form['old_type'])) {
     $type = $form['old_type']['#value'];
   }
-  
+ 
   $id = 'uc_product_add_to_cart_form_'. $form['nid']['#value'];
   switch ($form_id) {
     // Here, we allow for a per-node search block.
@@ -89,7 +89,7 @@ function uc_custom_price_form_alter(&$fo
     case $type .'_node_form':
       $node = node_load($form['nid']['#value']);
       $product_types = uc_product_node_info();
-      if (isset($product_types[$form['#node']->type])) {
+      if (isset($product_types[$node->type])) {
         $form['custom_price_fieldset'] = array(
           '#type' => 'fieldset',
           '#title' => t('Custom Price Calculation'),
@@ -101,10 +101,41 @@ function uc_custom_price_form_alter(&$fo
           '#type' => 'textarea',
           '#title' => t('Custom Code'),
           '#description' => t('Enter the code to be used for dynamic price calculation.'),
-          '#default_value' => !empty($node->custom_code) ? $node->custom_code : '$item->price = $item->price;',
+          '#default_value' => !empty($node->custom_code) ? $node->custom_code :
+    variable_get('uc_custom_price_default_calculation', '$item->price = $item->price;'),
           '#access' => user_access('administer custom code'),
         );
       }
     break;
   }
 }
+
+function uc_custom_price_admin() {
+  $form = array();
+ 
+  $form['uc_custom_price_default_calculation'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Default price calculation code'),
+    '#default_value' => variable_get('uc_custom_price_default_calculation', '$item->price = $item->price;'),
+    '#description' => t('Default code for dynamic price calculation.'),
+    '#required' => TRUE,
+  );
+ 
+  return system_settings_form($form);
+}
+
+function uc_custom_price_menu() {
+
+  $items = array();
+
+  $items['admin/store/settings/custom-price'] = array(
+    'title' => t('Custom price settings'),
+    'description' => t('Settings for the dynamic custom price calculation'),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('uc_custom_price_admin'),
+    'access arguments' => array('administer custom code'),
+    'type' => MENU_NORMAL_ITEM,
+   );
+
+  return $items;
+}
\ No newline at end of file
