You are here

function commerce_cart_block_view in Commerce Core 7

Implements hook_block_view().

File

modules/cart/commerce_cart.module, line 670
Implements the shopping cart system and add to cart features.

Code

function commerce_cart_block_view($delta) {
  global $user;

  // Prepare the display of the default Shopping Cart block.
  if ($delta == 'cart') {

    // First check to ensure there are products in the shopping cart.
    if ($order = commerce_cart_order_load($user->uid)) {
      $wrapper = entity_metadata_wrapper('commerce_order', $order);

      // If there are one or more products in the cart...
      if (commerce_line_items_quantity($wrapper->commerce_line_items, commerce_product_line_item_types()) > 0) {

        // Build the variables array to send to the cart block template.
        $variables = array(
          'order' => $order,
          'contents_view' => commerce_embed_view('commerce_cart_block', 'default', array(
            $order->order_id,
          ), $_GET['q']),
        );
        $content = theme('commerce_cart_block', $variables);
      }
    }
    if (empty($content)) {

      // Default to an empty cart block message.
      $content = theme('commerce_cart_empty_block');
    }
    return array(
      'subject' => t('Shopping cart'),
      'content' => $content,
    );
  }
}