function uc_attribute_uc_product_description in Ubercart 8.4
Same name and namespace in other branches
- 7.3 uc_attribute/uc_attribute.module \uc_attribute_uc_product_description()
Implements hook_uc_product_description().
File
- uc_attribute/
uc_attribute.module, line 388 - Ubercart Attribute module.
Code
function uc_attribute_uc_product_description($product) {
$description = [
'attributes' => [
'#product' => [
'#type' => 'value',
'#value' => $product,
],
'#theme' => 'uc_product_attributes',
'#weight' => 1,
],
];
$desc =& $description['attributes'];
// Cart version of the product has numeric attribute => option values so we
// need to retrieve the right ones.
$weight = 0;
if ($product instanceof CartItemInterface) {
foreach (_uc_cart_product_get_options($product) as $option) {
if (!isset($desc[$option['aid']])) {
$desc[$option['aid']]['#attribute_name'] = $option['attribute'];
$desc[$option['aid']]['#options'] = [
$option['name'],
];
}
else {
$desc[$option['aid']]['#options'][] = $option['name'];
}
$desc[$option['aid']]['#weight'] = $weight++;
}
}
elseif (!empty($product->data->attributes)) {
foreach ($product->data->attributes as $attribute => $option) {
$desc[] = [
'#attribute_name' => $attribute,
'#options' => $option,
'#weight' => $weight++,
];
}
}
return $description;
}