You are here

function uc_dropdown_attributes_class_create_dependency in Dropdown Attributes 6

Same name and namespace in other branches
  1. 8 uc_dropdown_attributes.module \uc_dropdown_attributes_class_create_dependency()
  2. 7 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

$pcid: Product class 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.

2 calls to uc_dropdown_attributes_class_create_dependency()
DropdownAttributeTestCase::testClassAttributeDependency in tests/uc_dropdown_attributes.test
Tests for dropdown attributes in product classes.
uc_dropdown_attributes_class_submit in ./dependent_dropdown.inc
Write form values out to the database table.

File

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

Code

function uc_dropdown_attributes_class_create_dependency($pcid, $aid, $parent_aid, $options, $required) {
  $record = new stdClass();
  $record->pcid = $pcid;
  $record->aid = $aid;
  $record->parent_aid = $parent_aid;
  $record->parent_values = serialize($options);
  $record->required = $required;
  $success = drupal_write_record('uc_dropdown_classes', $record);

  // Need to check to make sure attribute is not required all the time
  $query = 'SELECT pcid, aid, required FROM {uc_class_attributes}
    WHERE pcid="%s" AND aid=%d';
  $result = db_query($query, $pcid, $aid);
  $item = db_fetch_object($result);
  if ($item->required == 1) {
    $record = new stdClass();
    $record->pcid = $item->pcid;
    $record->aid = $item->aid;
    $record->required = 0;
    drupal_write_record('uc_class_attributes', $record, array(
      'pcid',
      'aid',
    ));
  }
  return $success;
}