function _uc_cart_product_get_options in Ubercart 8.4
Same name and namespace in other branches
- 5 uc_attribute/uc_attribute.module \_uc_cart_product_get_options()
- 6.2 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
mixed $item: A product node, a cart item or an ordered product object.
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 1089 - Ubercart Attribute module.
Code
function _uc_cart_product_get_options($item) {
if ($item instanceof NodeInterface) {
$node = $item;
$attributes = $item->data['attributes'];
}
else {
$node = $item->nid->entity;
$attributes = $item->data->attributes;
}
$options = [];
$index = 0;
if (!empty($attributes)) {
foreach ($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] = [
'attribute' => $name,
'aid' => $aid,
'oid' => 0,
'name' => $selected,
'cost' => 0,
'price' => 0,
'weight' => 0,
];
}
$index++;
}
}
}
return $options;
}