You are here

public function OrderTotal::render in Commerce Core 8.2

Render the area.

Parameters

bool $empty: (optional) Indicator if view result is empty or not. Defaults to FALSE.

Return value

array In any case we need a valid Drupal render array to return.

Overrides AreaPluginBase::render

File

modules/order/src/Plugin/views/area/OrderTotal.php, line 72

Class

OrderTotal
Defines an order total area handler.

Namespace

Drupal\commerce_order\Plugin\views\area

Code

public function render($empty = FALSE) {
  if (!$empty || !empty($this->options['empty'])) {
    foreach ($this->view->argument as $name => $argument) {

      // First look for an order_id argument.
      if (!$argument instanceof NumericArgument) {
        continue;
      }
      if (!in_array($argument
        ->getField(), [
        'commerce_order.order_id',
        'commerce_order_item.order_id',
      ])) {
        continue;
      }

      /** @var \Drupal\commerce_order\Entity\OrderInterface $order */
      if ($order = $this->orderStorage
        ->load($argument
        ->getValue())) {
        $order_total = $order
          ->get('total_price')
          ->view([
          'label' => 'hidden',
          'type' => 'commerce_order_total_summary',
          'weight' => $this->position,
        ]);
        $order_total['#prefix'] = '<div data-drupal-selector="order-total-summary">';
        $order_total['#suffix'] = '</div>';
        return $order_total;
      }
    }
  }
  return [];
}