You are here

function hook_uc_product_description in Ubercart 8.4

Same name and namespace in other branches
  1. 7.3 uc_product/uc_product.api.php \hook_uc_product_description()

Returns a structured array representing the given product's description.

Modules that add data to cart items when they are selected should display it with this hook. The return values from each implementation will be sent through to hook_uc_product_description_alter() implementations and then all descriptions are rendered using drupal_render().

Parameters

$product: Product. Usually one of the values of the array returned by uc_cart_get_contents().

Return value

array A render array that can be fed into drupal_render().

1 function implements hook_uc_product_description()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

uc_attribute_uc_product_description in uc_attribute/uc_attribute.module
Implements hook_uc_product_description().
1 invocation of hook_uc_product_description()
uc_product_get_description in uc_product/uc_product.module
Returns HTML for the product description.

File

uc_product/uc_product.api.php, line 64
Hooks provided by the Product module.

Code

function hook_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 (empty($product->order_id)) {
    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++;
    }
  }
  else {
    foreach ((array) $product->data['attributes'] as $attribute => $option) {
      $desc[] = [
        '#attribute_name' => $attribute,
        '#options' => $option,
        '#weight' => $weight++,
      ];
    }
  }
  return $description;
}