function uc_dropdown_attributes_class_create_dependency in Dropdown Attributes 7
Same name and namespace in other branches
- 8 uc_dropdown_attributes.module \uc_dropdown_attributes_class_create_dependency()
- 6 uc_dropdown_attributes.module \uc_dropdown_attributes_class_create_dependency()
Create an attribute dependency for product classes.
A public function that creates and stores an attribute dependency for product classes.
Parameters
int $pcid: Product class ID.
int $aid: Attribute ID of the dependent (child) attribute.
int $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.
2 calls to uc_dropdown_attributes_class_create_dependency()
- UCDropdownAttributesTestCase::testClassAttributeDependency in tests/
uc_dropdown_attributes.test - Test for dropdown attributes in product classes.
- uc_dropdown_attributes_class_submit in ./
dependent_dropdown.inc - Form submission handler for uc_dropdown_attributes_class().
File
- ./
uc_dropdown_attributes.module, line 669 - Show/hide attributes based on the values of other attributes.
Code
function uc_dropdown_attributes_class_create_dependency($pcid, $aid, $parent_aid, $options, $required) {
$attribute = uc_attribute_load($aid);
$dep = db_insert('uc_dropdown_classes')
->fields(array(
'pcid' => $pcid,
'aid' => $aid,
'parent_aid' => $parent_aid,
'parent_values' => serialize($options),
'required' => $required,
))
->execute();
// Need to check to make sure attribute is not required all the time.
$sql = 'SELECT pcid, aid, required FROM {uc_class_attributes}
WHERE pcid=:pcid && aid=:aid';
$result = db_query($sql, array(
':pcid' => $pcid,
':aid' => $aid,
));
foreach ($result as $item) {
if ($item->required == 1) {
$dep = db_update('uc_class_attributes')
->fields(array(
'required' => 0,
))
->condition('pcid', $item->pcid)
->condition('aid', $item->aid)
->execute();
}
}
}