You are here

function _uc_varprice_feature_form in UC Variable Price 6

Same name and namespace in other branches
  1. 7 uc_varprice.module \_uc_varprice_feature_form()
2 calls to _uc_varprice_feature_form()
uc_varprice_feature_form in ./uc_varprice.module
uc_varprice_form_alter in ./uc_varprice.module
Implementation of hook_form_alter().

File

./uc_varprice.module, line 356
Defines a product feature to turn any product into a variable priced product.

Code

function _uc_varprice_feature_form($data = FALSE) {
  $form = array();
  $form['#validate'] = array(
    'uc_varprice_feature_form_validate',
  );
  $form['prices'] = array(
    '#type' => 'fieldset',
    '#title' => t('Price settings'),
  );
  $form['prices']['price_default'] = array(
    '#type' => 'textfield',
    '#title' => t('Default price'),
    '#size' => 8,
    '#description' => t('The default price for this variable priced product.'),
    '#default_value' => $data ? $data->price_default : variable_get('uc_varprice_global_default', '0'),
    '#field_prefix' => variable_get('uc_sign_after_amount', FALSE) ? '' : variable_get('uc_currency_sign', '$'),
    '#field_suffix' => variable_get('uc_sign_after_amount', FALSE) ? variable_get('uc_currency_sign', '$') : '',
  );
  $form['prices']['sel_fs'] = array(
    '#type' => 'fieldset',
    '#title' => t('Selectable price'),
  );
  $form['prices']['sel_fs']['selectable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable selectable variable prices'),
    '#description' => t('When enabled, visitors may select one of several pre-set values defined by you.'),
    '#default_value' => $data ? $data->selectable : FALSE,
  );
  $form['prices']['sel_fs']['sel_widget'] = array(
    '#type' => 'radios',
    '#title' => t('Selection widget type'),
    '#options' => array(
      'radios' => t('Radio buttons'),
      'select' => t('Drop-down menu'),
    ),
    '#default_value' => $data ? $data->sel_widget : 'radios',
  );
  $sel_options_array = array();
  if ($data && $data->sel_options) {
    foreach ($data->sel_options as $key => $val) {
      $sel_options_array[] = "{$key}|{$val}";
    }
  }
  $form['prices']['sel_fs']['sel_options'] = array(
    '#type' => 'textarea',
    '#title' => t('Selectable prices'),
    '#description' => t('Enter one price per line, without currency symbols. If both selectable and arbitrary prices are enabled, an &ldquo;Other&rdquo; option will be automatically added to the end; when selected, the field to enter an arbitrary price will become available. If the value entered in the &ldquo;Default price&rdquo; field above matches one of these values, that option will be the default value of the price selection widget. You can also enter a price on each line in the format key|label, where the key is the price, and the label is is what you want displayed to end users. Example: "100|Sustainer ($100)". If you want to have more than one option at the same price but with different display text, you can add a colon and an optional unique identifier string after the price. Example:<br />100:School A|Sustainer from School A ($100)<br />100:School B|Sustainer from School B ($100)'),
    '#default_value' => implode("\n", $sel_options_array),
    '#field_prefix' => variable_get('uc_sign_after_amount', FALSE) ? '' : variable_get('uc_currency_sign', '$'),
    '#field_suffix' => variable_get('uc_sign_after_amount', FALSE) ? variable_get('uc_currency_sign', '$') : '',
  );
  $form['prices']['arb_fs'] = array(
    '#type' => 'fieldset',
    '#title' => t('Arbitrary price'),
  );
  $form['prices']['arb_fs']['arbitrary'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable arbitrary variable prices'),
    '#description' => t('When enabled, visitors will be able to enter any arbitrary price for this product, within the limits specified below.'),
    '#default_value' => $data ? $data->arbitrary : TRUE,
  );
  $form['prices']['arb_fs']['price_minimum'] = array(
    '#type' => 'textfield',
    '#title' => t('Minimum price'),
    '#size' => 8,
    '#description' => t('The minimum price required for this product to be added to the cart.<br />Leave blank for no minimum.'),
    '#default_value' => $data ? $data->price_minimum : '',
    '#field_prefix' => variable_get('uc_sign_after_amount', FALSE) ? '' : variable_get('uc_currency_sign', '$'),
    '#field_suffix' => variable_get('uc_sign_after_amount', FALSE) ? variable_get('uc_currency_sign', '$') : '',
  );
  $form['prices']['arb_fs']['price_maximum'] = array(
    '#type' => 'textfield',
    '#title' => t('Maximum price'),
    '#size' => 8,
    '#description' => t('The maximum price allowed for this product to be added to the cart.<br />Leave blank for no maximum.'),
    '#default_value' => $data ? $data->price_maximum : '',
    '#field_prefix' => variable_get('uc_sign_after_amount', FALSE) ? '' : variable_get('uc_currency_sign', '$'),
    '#field_suffix' => variable_get('uc_sign_after_amount', FALSE) ? variable_get('uc_currency_sign', '$') : '',
  );
  $form['titles'] = array(
    '#type' => 'fieldset',
    '#title' => t('Add to cart form element titles'),
    '#description' => t('Use these settings to adjust the normal titles of add to cart form elements for variable priced products.'),
  );
  $form['titles']['override_add_to_cart_title'] = array(
    '#type' => 'checkbox',
    '#title' => t('Override the title of the add to cart button.'),
    '#description' => t('Defaults to <em>Add to cart</em>. For multilingual sites, use <a href="!url">String Overrides</a> instead.', array(
      '!url' => url('http://drupal.org/project/stringoverrides', array(
        'absolute' => TRUE,
      )),
    )),
    '#default_value' => $data ? !empty($data->add_to_cart_title) : FALSE,
    '#attributes' => array(
      'class' => 'override-checkbox',
    ),
  );
  $form['titles']['add_to_cart_title'] = array(
    '#type' => 'textfield',
    '#title' => t('Add to cart button title'),
    '#default_value' => $data && !empty($data->add_to_cart_title) ? $data->add_to_cart_title : t('Add to cart'),
  );
  $form['titles']['override_amount_title'] = array(
    '#type' => 'checkbox',
    '#title' => t('Override the title of the amount field for the price on the add to cart form.'),
    '#description' => t('Defaults to <em>Amount</em>. For multilingual sites, use <a href="!url">String Overrides</a> instead.', array(
      '!url' => url('http://drupal.org/project/stringoverrides', array(
        'absolute' => TRUE,
      )),
    )),
    '#default_value' => $data ? !empty($data->amount_title) : FALSE,
    '#attributes' => array(
      'class' => 'override-checkbox',
    ),
  );
  $form['titles']['amount_title'] = array(
    '#type' => 'textfield',
    '#title' => t('Amount field title'),
    '#default_value' => $data && !empty($data->amount_title) ? $data->amount_title : t('Amount'),
  );
  return $form;
}