function uc_attribute_subject_save in Ubercart 7.3
Same name and namespace in other branches
- 8.4 uc_attribute/uc_attribute.module \uc_attribute_subject_save()
- 6.2 uc_attribute/uc_attribute.module \uc_attribute_subject_save()
Saves a product/class attribute.
Parameters
&$attribute: The product/class attribute.
string $type: Is this a product or a class?
string $id: The product/class ID.
bool $save_options: Save the product/class attribute's options, too?
Return value
int The integer result from drupal_write_record().
10 calls to uc_attribute_subject_save()
- UbercartAttributeCheckoutTestCase::testAttributeAddToCart in uc_attribute/
tests/ uc_attribute_checkout.test - Tests that product in cart has the selected attribute option.
- UbercartAttributeTestCase::testAttributeAPI in uc_attribute/
tests/ uc_attribute.test - Tests the basic attribute API.
- UbercartAttributeTestCase::testAttributeUIClassAttributeOptionOverview in uc_attribute/
tests/ uc_attribute.test - Tests the product class attribute option user interface.
- UbercartAttributeTestCase::testAttributeUIClassAttributeOverview in uc_attribute/
tests/ uc_attribute.test - Tests the product class attribute user interface.
- UbercartAttributeTestCase::testAttributeUIProductAdjustments in uc_attribute/
tests/ uc_attribute.test - Tests the "product adjustments" page.
File
- uc_attribute/
uc_attribute.module, line 867 - Ubercart Attribute module.
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'],
) : array();
// 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 (!empty($attribute->options) && 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($sql['attr_table'], $attribute, $key);
return $result;
}