function uc_product_view in Ubercart 7.3
Same name and namespace in other branches
- 5 uc_product/uc_product.module \uc_product_view()
- 6.2 uc_product/uc_product.module \uc_product_view()
Implements hook_view().
File
- uc_product/
uc_product.module, line 714 - The product module for Ubercart.
Code
function uc_product_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 -- cf. entity_prepare_view().
$variant = empty($node->variant) ? _uc_product_get_variant($node) : $node;
// Skip the add to cart form in comment reply forms.
if (arg(0) != 'comment' && arg(1) != 'reply') {
// Build the 'add to cart' form, and use the updated variant based on data
// provided by the form (e.g. attribute default options).
if (module_exists('uc_cart') && $variant->nid && empty($variant->data['display_only'])) {
$add_to_cart_form = drupal_get_form('uc_product_add_to_cart_form_' . $variant->nid, $variant);
if (variable_get('uc_product_update_node_view', FALSE)) {
$variant = $add_to_cart_form['node']['#value'];
}
}
}
$node->content['display_price'] = array(
'#theme' => 'uc_product_price',
'#value' => isset($variant->price) ? $variant->price : $variant->sell_price,
'#suffixes' => array(),
'#attributes' => array(
'class' => array(
'display-price',
'uc-product-' . $node->nid,
),
),
);
$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(
'list-price',
),
),
);
$node->content['cost'] = array(
'#theme' => 'uc_product_price',
'#title' => t('Cost:'),
'#value' => $variant->cost,
'#attributes' => array(
'class' => array(
'cost',
'uc-product-' . $node->nid,
),
),
'#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(
'sell-price',
),
),
);
$node->content['weight'] = array(
'#theme' => 'uc_product_weight',
'#amount' => $variant->weight,
'#units' => $variant->weight_units,
'#view_mode' => $view_mode,
'#attributes' => array(
'class' => array(
'uc-product-' . $node->nid,
),
),
);
$node->content['dimensions'] = array(
'#theme' => 'uc_product_dimensions',
'#length' => $variant->length,
'#width' => $variant->width,
'#height' => $variant->height,
'#units' => $variant->length_units,
'#view_mode' => $view_mode,
);
if (isset($add_to_cart_form)) {
$node->content['add_to_cart'] = array(
'#theme' => 'uc_product_add_to_cart',
'#view_mode' => $view_mode,
'#form' => $add_to_cart_form,
);
}
$node->content['#node'] = $variant;
return $node;
}