You are here

function _uc_dropdown_attributes_order_product_kit_build in Dropdown Attributes 7

Same name and namespace in other branches
  1. 8 uc_dropdown_attributes.module \_uc_dropdown_attributes_order_product_kit_build()

Form build for product kits for the order page.

Callback for $form['#after_build'] for products. Adds the CSS to hide the dependent attributes.

1 string reference to '_uc_dropdown_attributes_order_product_kit_build'
uc_dropdown_attributes_form_uc_order_edit_form_alter in ./uc_dropdown_attributes.module
Implements hook_form_FORM_ID_alter() for uc_order_edit_form().

File

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

Code

function _uc_dropdown_attributes_order_product_kit_build($form, &$form_state) {
  foreach ($form['product_controls']['sub_products'] as $nid => $product) {
    if (is_numeric($nid)) {
      $type = uc_dropdown_attributes_dependency_type($nid);
      switch ($type) {
        case 'node':
          $sql = 'SELECT aid, parent_aid, parent_values, required
            FROM {uc_dropdown_attributes} WHERE nid=:nid';
          $attributes = db_query($sql, array(
            ':nid' => $nid,
          ));
          if (isset($form_state['triggering_element']) && $nid == $form_state['triggering_element']['#parents'][2]) {
            $parents = $form_state['triggering_element']['#parents'];
            $parent_aid = $parents[count($parents) - 1];
            $parent_value = $form_state['triggering_element']['#value'];
            uc_dropdown_attributes_remove_values($parent_aid, $parent_value, $nid, 'node', $form_state['values']['product_controls']['sub_products'][$nid]);
          }
          uc_dropdown_attributes_order_attribute_display($attributes, $form['product_controls']['sub_products'][$nid]['attributes'], $form_state['values']['product_controls']['sub_products'][$nid]['attributes']);
          break;
        case 'class':
          $sql = 'SELECT aid, parent_aid, parent_values, required
            FROM {uc_dropdown_classes} WHERE pcid=:pcid';
          $pcid = uc_dropdown_attributes_get_type($nid);
          $attributes = db_query($sql, array(
            ':pcid' => $pcid,
          ));
          if (isset($form_state['triggering_element']) && $nid == $form_state['triggering_element']['#parents'][2]) {
            $parents = $form_state['triggering_element']['#parents'];
            $parent_aid = $parents[count($parents) - 1];
            $parent_value = $form_state['triggering_element']['#value'];

            // Note that values are stored in input, not values.
            uc_dropdown_attributes_remove_values($parent_aid, $parent_value, $pcid, 'class', $form_state['input']['product_controls']['sub_products'][$nid]);
          }
          uc_dropdown_attributes_order_attribute_display($attributes, $form['product_controls']['sub_products'][$nid]['attributes'], $form_state['values']['product_controls']['sub_products'][$nid]['attributes']);
          break;
      }
    }
  }
  return $form;
}