You are here

function uc_dropdown_attributes_product_alter in Dropdown Attributes 6

Same name and namespace in other branches
  1. 8 uc_dropdown_attributes.module \uc_dropdown_attributes_product_alter()
  2. 7 uc_dropdown_attributes.module \uc_dropdown_attributes_product_alter()

Alter products in preparation for drop down attributes.

1 call to uc_dropdown_attributes_product_alter()
uc_dropdown_attributes_form_alter in ./uc_dropdown_attributes.module
Implements hook_form_alter().

File

./uc_dropdown_attributes.module, line 114
Show/hide attributes based on the values of other attributes.

Code

function uc_dropdown_attributes_product_alter($nid, &$form_attributes, $type) {
  switch ($type) {
    case 'node':
      $sql = 'SELECT aid, required FROM {uc_dropdown_attributes} WHERE nid=%d';
      $attributes = db_query($sql, $nid);
      break;
    case 'class':
      $sql = 'SELECT aid, required FROM {uc_dropdown_classes} WHERE pcid=%d';
      $pcid = uc_dropdown_attributes_get_type($nid);
      $attributes = db_query($sql, $pcid);
      break;
  }
  while ($attribute = db_fetch_object($attributes)) {
    if ($attribute->required) {
      switch ($form_attributes[$attribute->aid]['#type']) {
        case 'select':
          if (count($form_attributes[$attribute->aid]['#options'])) {
            $form_attributes[$attribute->aid]['#options'] = array(
              '' => t('Please select'),
            ) + $form_attributes[$attribute->aid]['#options'];
            unset($form_attributes[$attribute->aid]['#default_value']);
          }
          break;
        case 'radios':
          if (count($form_attributes[$attribute->aid]['#options'])) {
            unset($form_attributes[$attribute->aid]['#default_value']);
          }
          break;
        case 'textfield':
          unset($form_attributes[$attribute->aid]['#default_value']);
          break;
        default:
      }
    }
  }
}