You are here

function uc_product_kit_view in Ubercart 7.3

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

Implements hook_view().

File

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

Code

function uc_product_kit_view($node, $view_mode) {

  // Give modules a chance to alter this product.  If it is a variant, this
  // will have been done already by uc_product_load_variant(), so we check a
  // flag to be sure not to alter twice.
  $variant = empty($node->variant) ? uc_product_load_variant($node->nid) : $node;
  if (module_exists('uc_cart') && empty($variant->data['display_only'])) {
    $add_to_cart_form = drupal_get_form('uc_product_kit_add_to_cart_form_' . $variant->nid, clone $variant);
    if (variable_get('uc_product_update_node_view', FALSE)) {
      $variant = $add_to_cart_form['node']['#value'];
    }
  }

  // Calculate the display price.
  $display_price = 0;
  $suffixes = array();
  if ($node->mutable != UC_PRODUCT_KIT_MUTABLE) {

    // If this is a non-mutable kit, then sum the display price of each of the
    // component products.
    foreach ($variant->products as $product) {
      $build = node_view($product, $view_mode);
      $display_price += $build['display_price']['#value'] * $product->qty;
      $suffixes += $build['display_price']['#suffixes'];
    }
  }
  else {

    // For mutable, just use the price.
    $display_price = $variant->price;
    $suffixes = array();
  }
  $node->content['display_price'] = array(
    '#theme' => 'uc_product_price',
    '#value' => $display_price,
    '#suffixes' => $suffixes,
    '#attributes' => array(
      'class' => array(
        'product-kit',
        'display-price',
      ),
    ),
  );
  $node->content['model'] = array(
    '#theme' => 'uc_product_model',
    '#model' => $variant->model,
    '#view_mode' => $view_mode,
  );
  $node->content['list_price'] = array(
    '#theme' => 'uc_product_price',
    '#title' => t('List price:'),
    '#value' => $variant->list_price,
    '#attributes' => array(
      'class' => array(
        'product-kit',
        'list-price',
      ),
    ),
  );
  $node->content['cost'] = array(
    '#theme' => 'uc_product_price',
    '#title' => t('Cost:'),
    '#value' => $variant->cost,
    '#attributes' => array(
      'class' => array(
        'product-kit',
        'cost',
      ),
    ),
    '#access' => user_access('administer products'),
  );
  $node->content['sell_price'] = array(
    '#theme' => 'uc_product_price',
    '#title' => t('Price:'),
    '#value' => $variant->sell_price,
    '#attributes' => array(
      'class' => array(
        'product-kit',
        'sell-price',
      ),
    ),
  );
  $node->content['weight'] = array(
    '#theme' => 'uc_product_weight',
    '#amount' => $variant->weight,
    '#units' => $variant->weight_units,
    '#view_mode' => $view_mode,
  );
  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(
        '#markup' => '<div class="product-qty">' . theme('uc_product_kit_list_item', array(
          'product' => $product,
        )) . '</div>',
      );
      $node->content['products'][$product->nid]['#weight'] = $i++;
    }
  }
  if (isset($add_to_cart_form)) {
    $node->content['add_to_cart'] = array(
      '#theme' => 'uc_product_kit_add_to_cart',
      '#view_mode' => $view_mode,
      '#form' => $add_to_cart_form,
    );
  }
  $node->content['#node'] = $variant;
  return $node;
}