You are here

function theme_basic_cart_render_cart_element in Basic cart 7.3

Same name and namespace in other branches
  1. 7 basic_cart.cart.inc \theme_basic_cart_render_cart_element()
  2. 7.2 basic_cart.theme.inc \theme_basic_cart_render_cart_element()

Theme implementation for rendering the cart element.

1 theme call to theme_basic_cart_render_cart_element()
basic_cart_cart_form in ./basic_cart.cart.inc
Shopping cart form.

File

./basic_cart.theme.inc, line 60

Code

function theme_basic_cart_render_cart_element($variables) {

  // Element name and nid.
  $name = $variables['form']['#name'];
  $nid = (int) str_replace(array(
    'cartcontents[',
    ']',
  ), '', $name);
  if (empty($nid)) {
    return '';
  }

  // Delete image.
  $vars = array(
    'path' => base_path() . drupal_get_path('module', 'basic_cart') . '/images/delete2.png',
    'alt' => t('Remove from cart'),
    'title' => t('Remove from cart'),
    'attributes' => array(
      'class' => 'basic-cart-delete-image-image',
    ),
  );
  $delete_link = l(theme('image', $vars), 'cart/remove/' . $nid, array(
    'html' => TRUE,
  ));

  // Getting the node for it's title and description.
  $node = basic_cart_get_cart($nid);

  // Node description.
  $desc = '';
  if (isset($node->basic_cart_node_description)) {
    $desc = drupal_strlen($node->basic_cart_node_description) > 50 ? truncate_utf8($node->basic_cart_node_description, 50) : $node->basic_cart_node_description;
  }

  // Price and currency.
  $unit_price = isset($node->basic_cart_unit_price) ? $node->basic_cart_unit_price : 0;
  $unit_price = basic_cart_price_format($unit_price);

  // Prefix.
  $prefix = '<div class="basic-cart-cart-contents row">';
  $prefix .= '  <div class="basic-cart-delete-image cell">' . $delete_link . '</div>';
  $prefix .= '  <div class="basic-cart-cart-node-title cell">' . l($node->title, 'node/' . $nid) . '<br />';
  $prefix .= '    <span class="basic-cart-cart-node-summary">' . $desc . '</span>';
  $prefix .= '  </div>';
  $prefix .= '  <div class="cell basic-cart-cart-unit-price"><strong>' . $unit_price . '</strong></div>';
  $prefix .= '  <div class="cell basic-cart-cart-x">x</div>';
  $prefix .= '  <div class="basic-cart-cart-quantity cell">';
  $prefix .= '    <div class="cell">';

  // Suffix.
  $suffix = '    </div>';
  $suffix .= '  </div>';
  $suffix .= '</div>';

  // Rendering the element as textfield.
  $quantity = theme('textfield', $variables['form']);

  // Full view return.
  return $prefix . $quantity . $suffix;
}