Hi,

I patched/extended this module so you have a settings dialog where you can define the default code for custom price calculation.
Right now, I don´t have the time to get CVS up and running and commit it myself. I would be glad if you can integrate this patch if you like it.

function uc_custom_price_form_alter(&$form, $form_state, $form_id) {
  if (isset($form['type'])) {
    $type = $form['type']['#value'];
  }
  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.
    // This is not shown if the content is globally blocked
    // Perhaps we want to include the reverse option (index a single node)?
    case $type .'_node_form':
      $node = node_load($form['nid']['#value']);
      $product_types = uc_product_node_info();
      if (isset($product_types[$node->type])) {
        $form['custom_price_fieldset'] = array(
          '#type' => 'fieldset',
          '#title' => t('Custom Price Calculation'),
          '#collapsible' => TRUE,
          '#collapsed' => TRUE,
          '#access' => user_access('administer custom code'),
        );
        $form['custom_price_fieldset']['custom_code'] = array(
          '#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 : 
		    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;
}

Cheers

CommentFileSizeAuthor
#4 set_default.patch2.42 KBrj

Comments

Alex Lawrence’s picture

Status: Patch (to be ported) » Needs review
lasbreyn’s picture

Hi Alex,
To what file in the module do I apply this patch?

finex’s picture

There is only one module file in this module.... so you should patch "uc_custom_price.module".

rj’s picture

StatusFileSize
new2.42 KB

I can confirm this works, and rolled it into a patch. Does not work for previously saved nodes.

tr’s picture

Category: task » feature
Status: Needs review » Fixed

I implemented something like this in the Drupal 7 version of the module then backported my changes to 6.x-1.x-dev. Instead of just one variable with one default price calculation, I created a variable for each product class, so you can set the default price calculation per-class.

Please try out the 6.x-1.x-dev version, and if you have any problems please continue this discussion in the thread at #843274: Content Type / Product Class Default. (That thread is more relevant to the actual change that was made.)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.