No replies
ambereyes's picture
Offline
Bug Finder
Joined: 05/19/2008
Juice: 98
Was this information Helpful?

I needed to be able to programatically deal with the shipping related form elements in the product node form. So I created a shipping fieldset within the uc_product_form function in the product module. I think this makes it easier to use form_alter to simplify product forms.

Katrina
www.ambereyes.net

// Add shipping fieldset to product form so I can collaspse programatically
  $form['base']['shipping'] = array('#type' => 'fieldset',
    '#title' => t('Shipping'),
    '#description' => t('Elements associated with shippable products.'),
    '#weight' => 15,
    '#collapsible' => TRUE,
  );
  $form['base']['shipping']['weight'] = array(
    '#weight' => 15,
    '#theme' => 'uc_product_form_weight',
  );
  $form['base']['shipping']['weight']['weight'] = array('#type' => 'textfield',
    '#title' => t('Weight'),
    '#default_value' => $node->weight,
    '#size' => 10,
    '#maxlength' => 15,
  );
  $units = array(
    'lb' => t('Pounds'),
    'kg' => t('Kilograms'),
    'oz' => t('Ounces'),
    'g' => t('Grams'),
  );
  $form['base']['shipping']['weight']['weight_units'] = array('#type' => 'select',
    '#title' => t('Unit of measurement'),
    '#default_value' => $node->weight_units ? $node->weight_units : variable_get('uc_weight_unit', 'lb'),
    '#options' => $units,
  );
  $form['base']['shipping']['dimensions'] = array('#type' => 'fieldset',
    '#title' => t('Dimensions'),
    '#description' => t('Physical dimensions of the packaged product.'),
    '#weight' => 20,
    '#theme' => 'uc_product_dimensions_form',
  );
  $form['base']['shipping']['dimensions']['length_units'] = array('#type' => 'select',
    '#title' => t('Units of measurement'),
    '#options' => array(
      'in' => t('Inches'),
      'ft' => t('Feet'),
      'cm' => t('Centimeters'),
      'mm' => t('Millimeters'),
    ),
    '#default_value' => $node->length_units ? $node->length_units : variable_get('uc_length_unit', 'in'),
  );
  $form['base']['shipping']['dimensions']['length'] = array('#type' => 'textfield',
    '#title' => t('Length'),
    '#default_value' => $node->length,
    '#size' => 10,
  );
  $form['base']['shipping']['dimensions']['width'] = array('#type' => 'textfield',
    '#title' => t('Width'),
    '#default_value' => $node->width,
    '#size' => 10,
  );
  $form['base']['shipping']['dimensions']['height'] = array('#type' => 'textfield',
    '#title' => t('Height'),
    '#default_value' => $node->height,
    '#size' => 10,
  );