You are here

function uc_product_kit_view in Ubercart 6.2

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

Implements hook_view().

File

uc_product_kit/uc_product_kit.module, line 616
The product kit module for Ubercart.

Code

function uc_product_kit_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,
  ));
  $context = array(
    'revision' => 'themed',
    'type' => 'product',
    'class' => array(
      'product-kit',
    ),
    'subject' => array(
      'node' => $node,
    ),
  );
  if (module_exists('imagecache') && ($field = variable_get('uc_image_product_kit', '')) && isset($node->{$field}) && file_exists($node->{$field}[0]['filepath'])) {
    $node->content['image'] = array(
      '#value' => theme('uc_product_image', $node->{$field}),
      '#access' => $enabled['image'],
      '#weight' => $weight['image'],
    );
  }
  $context['class'][1] = 'display';
  $context['field'] = 'sell_price';
  $node->content['display_price'] = array(
    '#value' => uc_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),
      '#access' => $enabled['model'],
      '#weight' => $weight['model'],
    );
    $node->content['body']['#weight'] = 1;
    $context['class'][1] = 'list';
    $context['field'] = 'list_price';
    $node->content['list_price'] = array(
      '#value' => uc_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' => uc_price($node->cost, $context),
      '#access' => $enabled['cost'] && user_access('administer products'),
      '#weight' => $weight['cost'],
    );
  }
  else {
    $node->content['#attributes'] = array(
      'style' => 'display: inline',
    );
  }
  $context['class'][1] = 'sell';
  $context['field'] = 'sell_price';
  $node->content['sell_price'] = array(
    '#value' => uc_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),
      '#access' => $enabled['weight'],
      '#weight' => $weight['weight'],
    );
    if ($node->mutable != UC_PRODUCT_KIT_UNMUTABLE_NO_LIST) {
      $node->content['products'] = array(
        '#weight' => 6,
      );
      $i = 0;
      foreach ($node->products as $product) {
        $node->content['products'][$product->nid]['qty'] = array(
          '#value' => '<div class="product-qty">' . theme('uc_product_kit_list_item', $product) . '</div>',
        );
        $node->content['products'][$product->nid]['#weight'] = $i++;
      }
    }
    if (module_exists('uc_cart')) {
      $node->content['add_to_cart'] = array(
        '#value' => theme('uc_product_kit_add_to_cart', $node),
        '#weight' => 10,
      );
    }
  }
  elseif (module_exists('uc_cart') && variable_get('uc_product_add_to_cart_teaser', TRUE)) {
    $node->content['add_to_cart'] = array(
      '#value' => theme('uc_product_kit_add_to_cart', $node),
      '#weight' => 10,
    );
  }
  return $node;
}