function uc_attribute_subject_save in Ubercart 6.2
Same name and namespace in other branches
- 8.4 uc_attribute/uc_attribute.module \uc_attribute_subject_save()
- 7.3 uc_attribute/uc_attribute.module \uc_attribute_subject_save()
Saves a product/class attribute.
Parameters
&$attribute: The product/class attribute.
$type: Is this a product or a class?
$id: The product/class ID.
$save_options: Save the product/class attribute's options, too?
Return value
The integer result from drupal_write_record().
8 calls to uc_attribute_subject_save()
- UbercartAttributeTestCase::testAttributeAPI in uc_attribute/
uc_attribute.test - Tests the basic attribute API.
- UbercartAttributeTestCase::testAttributeUIAttributeOptionsBulkEdit in uc_attribute/
uc_attribute.test - Tests the "bulk edit attribute options" user interface.
- UbercartAttributeTestCase::testAttributeUIClassAttributeOptionOverview in uc_attribute/
uc_attribute.test - Tests the product class attribute option user interface.
- UbercartAttributeTestCase::testAttributeUIClassAttributeOverview in uc_attribute/
uc_attribute.test - Tests the product class attribute user interface.
- UbercartAttributeTestCase::testAttributeUIProductAttributeBulkUpdate in uc_attribute/
uc_attribute.test - Tests the bulk product attribute update user interface.
File
- uc_attribute/
uc_attribute.module, line 903
Code
function uc_attribute_subject_save(&$attribute, $type, $id, $save_options = FALSE) {
$sql = uc_attribute_type_info($type);
// Insert or update?
$key = uc_attribute_subject_exists($attribute->aid, $type, $id) ? array(
'aid',
$sql['id'],
) : NULL;
// First, save the options. First because if this is an insert, we'll set
// a default option for the product/class attribute.
if ($save_options && is_array($attribute->options)) {
foreach ($attribute->options as $option) {
// Sanity check!
$option = (object) $option;
uc_attribute_subject_option_save($option, $type, $id);
}
// Is this an insert? If so, we'll set the default option.
if (empty($key)) {
$default_option = 0;
// Make the first option (if any) the default.
if (is_array($attribute->options)) {
$option = (object) reset($attribute->options);
$default_option = $option->oid;
}
$attribute->default_option = $default_option;
}
}
// Merge in the product/class attribute's ID and save.
$attribute->{$type == 'product' ? 'nid' : 'pcid'} = $id;
$result = drupal_write_record(trim($sql['attr_table'], '{}'), $attribute, $key);
return $result;
}