function _uc_cart_product_get_options in Ubercart 6.2
Same name and namespace in other branches
- 8.4 uc_attribute/uc_attribute.module \_uc_cart_product_get_options()
- 5 uc_attribute/uc_attribute.module \_uc_cart_product_get_options()
- 7.3 uc_attribute/uc_attribute.module \_uc_cart_product_get_options()
Gets the options chosen for a product that is in the cart.
Parameters
$item: An element of the array returned by uc_cart_get_contents.
Return value
Array of options chosen by a customer, indexed by attribute ids. Each element stores the attribute name and the option object chosen.
4 calls to _uc_cart_product_get_options()
- hook_product_description in docs/
hooks.php - Returns a structured array representing the given product's description.
- uc_attribute_cart_item in uc_attribute/
uc_attribute.module - Implements hook_cart_item().
- uc_attribute_order_product_alter in uc_attribute/
uc_attribute.module - Implements hook_order_product_alter().
- uc_attribute_product_description in uc_attribute/
uc_attribute.module - Implements hook_product_description().
File
- uc_attribute/
uc_attribute.module, line 1222
Code
function _uc_cart_product_get_options($item) {
$options = array();
$data = $item->data;
$node = node_load($item->nid);
$index = 0;
if (!empty($data['attributes']) && is_array($data['attributes'])) {
foreach ($data['attributes'] as $aid => $selected) {
if (isset($node->attributes[$aid])) {
$attribute = $node->attributes[$aid];
$name = _uc_attribute_get_name($attribute);
// Only discrete options can affect the price of an item.
if ($attribute->display && count($attribute->options)) {
// There may be many selected options, or just one.
foreach ((array) $selected as $oid) {
if ($oid > 0) {
$options[$index] = (array) $attribute->options[$oid];
$options[$index]['attribute'] = $name;
$index++;
}
}
}
else {
// Handle textfield attributes.
$options[$index] = array(
'attribute' => $name,
'aid' => $aid,
'oid' => 0,
'name' => $selected,
'cost' => 0,
'price' => 0,
'weight' => 0,
);
}
$index++;
}
}
}
else {
$options = array();
}
return $options;
}