You are here

function basic_cart_node_view in Basic cart 7.2

Same name and namespace in other branches
  1. 7 basic_cart.module \basic_cart_node_view()

Implements hook_node_view().

File

./basic_cart.module, line 132

Code

function basic_cart_node_view($node, $view_mode, $langcode) {

  // Check if the current user has access to basic cart.
  if (user_access('use basic cart')) {

    // Getting node types.
    $node_types = variable_get('basic_cart_content_types');
    if (!is_array($node_types) || empty($node_types)) {
      return;
    }

    // Add to cart button.
    if (!empty($node_types[$node->type]) && in_array($node->type, $node_types)) {

      // Price field.
      $price = field_get_items('node', $node, 'price');
      $price = check_plain($price[0]['value']);

      // Price format.
      $price = basic_cart_price_format($price);
      $node->content['price'] = array(
        '#markup' => theme('basic_cart_price', array(
          'price' => $price,
        )),
        '#weight' => 30,
      );
      $node->content['basic_cart_add_to_cart'] = array(
        '#markup' => theme('basic_cart_add_to_cart', array(
          'nid' => $node->nid,
        )),
        '#weight' => 50,
      );
    }
  }
}