function uc_dropdown_attributes_order_product_alter in Dropdown Attributes 7
Same name and namespace in other branches
- 8 uc_dropdown_attributes.module \uc_dropdown_attributes_order_product_alter()
Alter products on oder page in preparation for drop down attributes.
Adds the 'Please select' and removes the default value. Ubercart does this for required attributes but since these attributes can no longer be required if the attributes are dependent then this reproduces the same thing.
Parameters
int $nid: Node ID.
array $form_attributes: Attributes part of the product form.
string $type: 'node' for dependencies defined on the node level; 'class' for dependencies defined on the product class.
1 call to uc_dropdown_attributes_order_product_alter()
File
- ./
uc_dropdown_attributes.module, line 831 - Show/hide attributes based on the values of other attributes.
Code
function uc_dropdown_attributes_order_product_alter($nid, &$form_attributes, $type) {
switch ($type) {
case 'node':
$sql = 'SELECT aid, parent_aid, required FROM {uc_dropdown_attributes}
WHERE nid=:nid';
$attributes = db_query($sql, array(
':nid' => $nid,
));
break;
case 'class':
$sql = 'SELECT aid, parent_aid, required FROM {uc_dropdown_classes}
WHERE pcid=:pcid';
$pcid = uc_dropdown_attributes_get_type($nid);
$attributes = db_query($sql, array(
':pcid' => $pcid,
));
break;
}
$parent_aids = array();
foreach ($attributes as $attribute) {
$parent_aids[$attribute->parent_aid] = $attribute->parent_aid;
if (isset($form_attributes[$attribute->aid]['#options']) && count($form_attributes[$attribute->aid]['#options']) && $attribute->required) {
switch ($form_attributes[$attribute->aid]['#type']) {
case 'select':
$form_attributes[$attribute->aid]['#options'] = array(
'' => t('Please select'),
) + $form_attributes[$attribute->aid]['#options'];
$form_attributes[$attribute->aid]['#default_value'] = '';
break;
case 'radios':
$form_attributes[$attribute->aid]['#default_value'] = '';
break;
case 'checkboxes':
$form_attributes[$attribute->aid]['#default_value'] = array();
break;
}
}
}
foreach ($parent_aids as $aid) {
$form_attributes[$aid]['#ajax'] = array(
'callback' => 'uc_dropdown_attributes_order_ajax_callback',
'wrapper' => $form_attributes['#id'],
);
}
}