theme_uc_cart_block_content

函数theme_uc_cart_block_content()位于uc_cart.module模块中

<?php
  theme_uc_cart_block_content()
?>

 

描述:

这个函数负责购物车区块的主题化。默认情况下,这是购物车中的项目列表,每个项目都链接到它对应的产品页面。它还包括“查看购物车”和“结算”链接。

返回值:

一个字符串,包含了购物车区块内容的HTML输出。

 

示例:

<?php
// The default function from uc_cart.module.
function theme_uc_cart_block_content() {
  global $user;

  if (variable_get('uc_cart_show_help_text', FALSE)) {
    $output = '<span class="cart-help-text">'
            . variable_get('uc_cart_help_text', t('Click title to display cart contents.'))
             .'</span>';
  }

  $output .= '<div id="block-cart-contents">';

  $items = uc_cart_get_contents();

  $item_count = 0;
  if (!empty($items)) {
    $output .= '<table class="cart-block-table">'
              .'<tbody class="cart-block-tbody">';
    foreach ($items as $item) {
      $output .= '<tr class="cart-block-item"><td class="cart-block-item-qty">'. $item->qty .'x</td>'
               . '<td class="cart-block-item-title">'. l($item->title, 'node/'. $item->nid) .'</td>'
               . '<td class="cart-block-item-price">'. uc_currency_format($item->price) .'</td></tr>';
      if (is_array($item->data['attributes']) && !empty($item->data['attributes'])) {
        $display_item = module_invoke($item->module, 'cart_display', $item);
        $output .= '<tr><td colspan="3">'. $display_item['options']['#value'] .'</td></tr>';
      }
      $total += ($item->price) * $item->qty;
      $item_count += $item->qty;
    }

    $output .= '</tbody></table>';
  }
  else {
    $output .= '<p>'. t('There are no products in your shopping cart.') .'</p>';
  }

  $output .= '</div>';

  $item_text = format_plural($item_count, '1 Item', '@count Items');
  $view = '('. l(t('View cart'), 'cart', array('rel' => 'nofollow')) .')';
  if (variable_get('uc_checkout_enabled', TRUE)) {
    $checkout = ' ('. l(t('Checkout'), 'cart/checkout', array('rel' => 'nofollow')) .')';
  }
  $output .= '<table class="cart-block-summary-table"><tbody class="cart-block-summary-tbody">'
            .'<tr class="cart-block-summary-tr"><td class="cart-block-summary-items">'
            . $item_text .'</td><td class="cart-block-summary-total">'
            .'<strong>'. t('Total:') .'</strong> '. uc_currency_format($total) .'</td></tr>';
  if ($item_count > 0) {
    $output .= '<tr><td colspan="2" class="cart-block-summary-checkout">'. $view . $checkout .'</td></tr>';
  }
  $output .= '</tbody></table>';

  return $output;
}
?>

论坛: