You are here

public function OrderWeightTotal::render in Ubercart 8.4

Renders the field.

Parameters

\Drupal\views\ResultRow $values: The values retrieved from a single row of a view's query result.

Return value

string|\Drupal\Component\Render\MarkupInterface The rendered output. If the output is safe it will be wrapped in an object that implements MarkupInterface. If it is empty or unsafe it will be a string.

Overrides Weight::render

File

uc_order/src/Plugin/views/field/OrderWeightTotal.php, line 61

Class

OrderWeightTotal
Total weight field handler.

Namespace

Drupal\uc_order\Plugin\views\field

Code

public function render(ResultRow $values) {
  $oid = $values->{$this->aliases['order_id']};
  $order = Order::load($oid);
  $total = 0;
  foreach ($order->products as $product) {
    $unit_conversion = uc_weight_conversion($product->weight_units, $this->options['weight_units']);
    $total += $product->qty * $product->weight * $unit_conversion;
  }
  $this->field_alias = 'order_weight';
  $values->{$this->field_alias} = $total;
  if ($this->options['format'] == 'numeric') {
    return parent::render($values);
  }
  if ($this->options['format'] == 'uc_weight') {
    return uc_weight_format($values->{$this->field_alias}, $this->options['weight_units']);
  }
}