function uc_dropdown_attributes_product_create_dependency in Dropdown Attributes 6
Same name and namespace in other branches
- 8 uc_dropdown_attributes.module \uc_dropdown_attributes_product_create_dependency()
- 7 uc_dropdown_attributes.module \uc_dropdown_attributes_product_create_dependency()
Create an attribute dependency.
A public function that creates and stores an attribute dependency for a product.
Parameters
$nid: Node ID.
$aid: Attribute ID of the dependent (child) attribute.
$parent_aid: Attribute ID of the parent attribute.
array $options: Array of the Option IDs that trigger the dependent attribute.
bool $required: TRUE if the dependent (child) attribute is required when it appears and FALSE if it is not required.
Return value
boolean TRUE if attribute dependency is saved; otherwise, FALSE.
2 calls to uc_dropdown_attributes_product_create_dependency()
- DropdownAttributeTestCase::testProductAttributeDependency in tests/
uc_dropdown_attributes.test - Tests for dropdown attributes in products.
- uc_dropdown_attributes_product_submit in ./
dependent_dropdown.inc - Write form values out to the database table.
File
- ./
uc_dropdown_attributes.module, line 328 - Show/hide attributes based on the values of other attributes.
Code
function uc_dropdown_attributes_product_create_dependency($nid, $aid, $parent_aid, $options, $required) {
$record = new stdClass();
$record->nid = $nid;
$record->aid = $aid;
$record->parent_aid = $parent_aid;
$record->parent_values = serialize($options);
$record->required = $required;
$success = drupal_write_record('uc_dropdown_attributes', $record);
// Need to check to make sure attribute is not required all the time
$query = 'SELECT nid, aid, required FROM {uc_product_attributes}
WHERE nid=%d AND aid=%d';
$result = db_query($query, $nid, $aid);
$item = db_fetch_object($result);
if ($item->required == 1) {
$record = new stdClass();
$record->nid = $item->nid;
$record->aid = $item->aid;
$record->required = 0;
drupal_write_record('uc_product_attributes', $record, array(
'nid',
'aid',
));
}
return $success;
}