You are here

function uc_product_view in Ubercart 5

Same name and namespace in other branches
  1. 6.2 uc_product/uc_product.module \uc_product_view()
  2. 7.3 uc_product/uc_product.module \uc_product_view()

Implementation of hook_view().

File

uc_product/uc_product.module, line 702
The product module for Ubercart.

Code

function uc_product_view($node, $teaser = 0, $page = 0) {
  $node = node_prepare($node, $teaser);
  $enabled = variable_get('uc_product_field_enabled', array(
    'image' => 1,
    'display_price' => 1,
    'model' => 1,
    'list_price' => 0,
    'cost' => 0,
    'sell_price' => 1,
    'weight' => 0,
    'dimensions' => 0,
    'add_to_cart' => 1,
  ));
  $weight = variable_get('uc_product_field_weight', array(
    'image' => -2,
    'display_price' => -1,
    'model' => 0,
    'list_price' => 2,
    'cost' => 3,
    'sell_price' => 4,
    'weight' => 5,
    'dimensions' => 6,
    'add_to_cart' => 10,
  ));

  //drupal_set_message('<pre>'. print_r($node->field_image_cache, true) .'</pre>');
  if (isset($node->field_image_cache) && file_exists($node->field_image_cache[0]['filepath'])) {
    $node->content['image'] = array(
      '#value' => theme('uc_product_image', $node->field_image_cache, $teaser, $page),
      '#access' => $enabled['image'] && module_exists('imagecache'),
      '#weight' => $weight['image'],
    );
  }
  $node->content['display_price'] = array(
    '#value' => theme('uc_product_display_price', $node->sell_price, $teaser, $page),
    '#access' => $enabled['display_price'],
    '#weight' => $weight['display_price'],
  );
  if (!$teaser) {
    $node->content['model'] = array(
      '#value' => theme('uc_product_model', $node->model, $teaser, $page),
      '#access' => $enabled['model'],
      '#weight' => $weight['model'],
    );
    $node->content['body']['#weight'] = 1;
    $node->content['list_price'] = array(
      '#value' => theme('uc_product_price', $node->list_price, 'list_price', $teaser, $page),
      '#access' => $enabled['list_price'],
      '#weight' => $weight['list_price'],
    );
    $node->content['cost'] = array(
      '#value' => theme('uc_product_price', $node->cost, 'cost', $teaser, $page),
      '#access' => $enabled['cost'] && user_access('administer products'),
      '#weight' => $weight['cost'],
    );
  }
  else {
    $node->content['#attributes'] = array(
      'style' => 'display: inline',
    );
  }
  $node->content['sell_price'] = array(
    '#value' => theme('uc_product_sell_price', $node->sell_price, $teaser, $page),
    '#access' => $enabled['sell_price'],
    '#weight' => $weight['sell_price'],
  );
  if (!$teaser) {
    $node->content['weight'] = array(
      '#value' => theme('uc_product_weight', $node->weight, $node->weight_units, $teaser, $page),
      '#access' => $enabled['weight'],
      '#weight' => $weight['weight'],
    );
    $node->content['dimensions'] = array(
      '#value' => theme('uc_product_dimensions', $node->length, $node->width, $node->height, $node->length_units, $teaser, $page),
      '#access' => $enabled['dimensions'],
      '#weight' => $weight['dimensions'],
    );
    if (module_exists('uc_cart')) {
      $node->content['add_to_cart'] = array(
        '#value' => theme('uc_product_add_to_cart', $node, $teaser, $page),
        '#access' => $enabled['add_to_cart'],
        '#weight' => $weight['add_to_cart'],
      );
    }
  }
  else {
    if (module_exists('uc_cart') && variable_get('uc_product_add_to_cart_teaser', true)) {
      $node->content['add_to_cart'] = array(
        '#value' => theme('uc_product_add_to_cart', $node, $teaser, $page),
        '#access' => $enabled['add_to_cart'],
        '#weight' => $weight['add_to_cart'],
      );
    }
  }

  //drupal_set_message('<pre>'. print_r($breadcrumb, true) .'</pre>');
  return $node;
}