You are here

function uc_product_view in Ubercart 6.2

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

Implements hook_view().

File

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

Code

function uc_product_view($node, $teaser = 0, $page = 0) {
  $node = node_prepare($node, $teaser);
  $enabled = uc_product_field_enabled();
  $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,
  ));
  $context = array(
    'revision' => 'themed',
    'type' => 'product',
    'class' => array(
      'product',
    ),
    'subject' => array(
      'node' => $node,
    ),
  );
  if (module_exists('imagecache') && ($field = variable_get('uc_image_' . $node->type, '')) && isset($node->{$field}) && file_exists($node->{$field}[0]['filepath'])) {
    $node->content['image'] = array(
      '#value' => theme('uc_product_image', $node->{$field}, $teaser, $page),
      '#access' => $enabled['image'],
      '#weight' => $weight['image'],
    );
  }
  $context['class'][1] = 'display';
  $context['field'] = 'sell_price';
  $node->content['display_price'] = array(
    '#value' => theme('uc_product_price', $node->sell_price, $context),
    '#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']['#value'] = theme('uc_product_body', $node->body, $teaser, $page);
    $node->content['body']['#weight'] = 1;
    $context['class'][1] = 'list';
    $context['field'] = 'list_price';
    $node->content['list_price'] = array(
      '#value' => theme('uc_product_price', $node->list_price, $context),
      '#access' => $enabled['list_price'],
      '#weight' => $weight['list_price'],
    );
    $context['class'][1] = 'cost';
    $context['field'] = 'cost';
    $node->content['cost'] = array(
      '#value' => theme('uc_product_price', $node->cost, $context),
      '#access' => $enabled['cost'] && user_access('administer products'),
      '#weight' => $weight['cost'],
    );
  }
  else {
    $node->content['body']['#value'] = theme('uc_product_body', $node->teaser, $teaser, $page);
    $node->content['#attributes'] = array(
      'style' => 'display: inline',
    );
  }
  $context['class'][1] = 'sell';
  $context['field'] = 'sell_price';
  $node->content['sell_price'] = array(
    '#value' => theme('uc_product_price', $node->sell_price, $context, array(
      'label' => !$teaser,
    )),
    '#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'],
      );
    }
  }
  elseif (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'],
    );
  }
  return $node;
}