function _uc_cart_product_get_options in Ubercart 7.3
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()
- 6.2 uc_attribute/uc_attribute.module \_uc_cart_product_get_options()
Gets the options chosen for a product that is in the cart.
Parameters
mixed $item: An element of the array returned by uc_cart_get_contents.
Return value
array Array of options chosen by a customer, indexed by attribute ids. Each element stores the attribute name and the option object chosen.
5 calls to _uc_cart_product_get_options()
- hook_uc_product_alter in uc_product/
uc_product.api.php - Make alterations to a specific variant of a product node.
- hook_uc_product_description in uc_product/
uc_product.api.php - Returns a structured array representing the given product's description.
- uc_attribute_uc_order_product_alter in uc_attribute/
uc_attribute.module - Implements hook_uc_order_product_alter().
- uc_attribute_uc_product_alter in uc_attribute/
uc_attribute.module - Implements hook_uc_product_alter().
- uc_attribute_uc_product_description in uc_attribute/
uc_attribute.module - Implements hook_uc_product_description().
File
- uc_attribute/
uc_attribute.module, line 1206 - Ubercart Attribute module.
Code
function _uc_cart_product_get_options($item) {
$options = array();
if (empty($item->data)) {
return $options;
}
$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;
}