You are here

function theme_uc_cart_review_table in Ubercart 8.4

Same name and namespace in other branches
  1. 7.3 uc_cart/uc_cart_checkout_pane.inc \theme_uc_cart_review_table()

Formats the cart contents table on the checkout page.

Parameters

array $variables: An associative array containing:

  • show_subtotal: TRUE or FALSE indicating if you want a subtotal row displayed in the table.
  • items: An associative array of cart item information containing:
    • qty: Quantity in cart.
    • title: Item title.
    • price: Item price.
    • desc: Item description.

Return value

string The HTML output for the cart review table.

1 string reference to 'theme_uc_cart_review_table'
uc_cart_theme in uc_cart/uc_cart.module
Implements hook_theme().
2 theme calls to theme_uc_cart_review_table()
CartPane::review in uc_cart/src/Plugin/Ubercart/CheckoutPane/CartPane.php
Returns the review contents of a checkout pane.
CartPane::view in uc_cart/src/Plugin/Ubercart/CheckoutPane/CartPane.php
Returns the contents of a checkout pane.

File

uc_cart/uc_cart.theme.inc, line 26
Theme functions for the uc_cart module.

Code

function theme_uc_cart_review_table(array $variables) {
  $items = $variables['items'];
  $show_subtotal = $variables['show_subtotal'];
  $subtotal = 0;

  // Set up table header.
  $header = [
    [
      'data' => t('Quantity'),
      'class' => [
        'qty',
      ],
    ],
    [
      'data' => t('Products'),
      'class' => [
        'products',
      ],
    ],
    [
      'data' => t('Price'),
      'class' => [
        'price',
      ],
    ],
  ];

  // Set up table rows.
  // @todo Replace with Views.
  foreach ($items as $item) {
    $subtotal += $item->price->value * $item->qty->value;
    $rows[] = [
      'data' => [
        [
          'data' => [
            '#theme' => 'uc_qty',
            '#qty' => $item->qty->value,
          ],
          'class' => [
            'qty',
          ],
        ],
        [
          'data' => [
            '#markup' => $item->title->value . uc_product_get_description($item),
          ],
          'class' => [
            'products',
          ],
        ],
        [
          'data' => [
            '#theme' => 'uc_price',
            '#price' => $item->price->value * $item->qty->value,
          ],
          'class' => [
            'price',
          ],
        ],
      ],
      'no_striping' => TRUE,
    ];
  }

  // Add the subtotal in the table footer.
  $footer = [];
  if ($show_subtotal) {
    $footer[] = [
      'data' => [
        // Cells.
        [
          'data' => [
            '#markup' => t('Subtotal:'),
          ],
          'colspan' => 2,
          'class' => [
            'subtotal-title',
          ],
        ],
        [
          'data' => [
            '#theme' => 'uc_price',
            '#price' => $subtotal,
          ],
          'class' => [
            'price',
          ],
        ],
      ],
      // Row attributes.
      'no_striping' => TRUE,
    ];
  }
  $table = [
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#footer' => $footer,
    '#attributes' => [
      'class' => [
        'cart-review',
      ],
    ],
  ];
  return drupal_render($table);
}