function uc_attribute_load in Ubercart 5
Same name and namespace in other branches
- 8.4 uc_attribute/uc_attribute.module \uc_attribute_load()
- 6.2 uc_attribute/uc_attribute.module \uc_attribute_load()
- 7.3 uc_attribute/uc_attribute.module \uc_attribute_load()
Load an attribute from the database.
Parameters
$attr_id: The id of the attribute.
$nid: Node id. If given, the attribute will have the options that have been assigned to that node for the attribute.
17 calls to uc_attribute_load()
- theme_uc_attribute in uc_attribute/
uc_attribute.module - Display formatted of data associated with attributes
- theme_uc_attribute_options in uc_attribute/
uc_attribute.module - Format an attribute and its options.
- uc_attribute_add_to_cart_data in uc_attribute/
uc_attribute.module - Stores the customer's choices in the cart.
- uc_attribute_condition_ordered_product_option in uc_attribute/
uc_attribute_workflow.inc - uc_attribute_delete_confirm in uc_attribute/
uc_attribute.module
File
- uc_attribute/
uc_attribute.module, line 1338
Code
function uc_attribute_load($attr_id, $nid = NULL, $type = '') {
if ($nid) {
switch ($type) {
case 'product':
$attribute = db_fetch_object(db_query("SELECT a.aid, a.name, a.ordering AS default_ordering, a.required AS default_required, a.display AS default_display, a.description, pa.default_option, pa.required, pa.ordering, pa.display FROM {uc_attributes} AS a LEFT JOIN {uc_product_attributes} AS pa ON a.aid = pa.aid AND pa.nid = %d WHERE a.aid = %d", $nid, $attr_id));
$result = db_query("SELECT po.nid, po.oid, po.cost, po.price, po.weight, po.ordering, ao.name, ao.aid FROM {uc_product_options} AS po LEFT JOIN {uc_attribute_options} AS ao ON po.oid = ao.oid AND nid = %d WHERE aid = %d ORDER BY po.ordering, ao.name", $nid, $attr_id);
break;
case 'class':
$attribute = db_fetch_object(db_query("SELECT a.aid, a.name, a.ordering AS default_ordering, a.required AS default_required, a.display AS default_display, a.description, ca.default_option, ca.required, ca.ordering, ca.display FROM {uc_attributes} AS a LEFT JOIN {uc_class_attributes} AS ca ON a.aid = ca.aid AND ca.pcid = '%s' WHERE a.aid = %d", $nid, $attr_id));
$result = db_query("SELECT co.pcid, co.oid, co.cost, co.price, co.weight, co.ordering, ao.name, ao.aid FROM {uc_class_attribute_options} AS co LEFT JOIN {uc_attribute_options} AS ao ON co.oid = ao.oid AND co.pcid = '%s' WHERE ao.aid = %d ORDER BY co.ordering, ao.name", $nid, $attr_id);
break;
default:
$attribute = db_fetch_object(db_query("SELECT * FROM {uc_attributes} WHERE aid = %d", $attr_id));
$result = db_query("SELECT * FROM {uc_attribute_options} WHERE aid = %d ORDER BY ordering, name", $attr_id);
break;
}
if (isset($attribute->default_ordering) && is_null($attribute->ordering)) {
$attribute->ordering = $attribute->default_ordering;
}
if (isset($attribute->default_required) && is_null($attribute->required)) {
$attribute->required = $attribute->default_required;
}
if (isset($attribute->default_display) && is_null($attribute->display)) {
$attribute->display = $attribute->default_display;
}
}
else {
$attribute = db_fetch_object(db_query("SELECT * FROM {uc_attributes} WHERE aid = %d", $attr_id));
$result = db_query("SELECT * FROM {uc_attribute_options} WHERE aid = %d ORDER BY ordering, name", $attr_id);
}
if ($attribute) {
$attribute->options = array();
while ($option = db_fetch_object($result)) {
$attribute->options[$option->oid] = $option;
}
}
return $attribute;
}