DisplayPrice.php in Ubercart 8.4
File
uc_product/src/Plugin/views/field/DisplayPrice.php
View source
<?php
namespace Drupal\uc_product\Plugin\views\field;
use Drupal\uc_store\Plugin\views\field\Price;
use Drupal\views\ResultRow;
use Drupal\node\Entity\Node;
class DisplayPrice extends Price {
protected function defineOptions() {
$options = parent::defineOptions();
$options['label']['default'] = $this
->t('Price');
return $options;
}
public function getValue(ResultRow $values, $field = NULL) {
$nid = parent::getValue($values, $field);
if (!is_null($nid)) {
$node = Node::load($nid);
return $node->price->value;
$node = node_view(Node::load($nid), 'teaser');
return $node['display_price']['#value'];
}
}
public function clickSort($order) {
$params = $this->options['group_type'] != 'group' ? [
'function' => $this->options['group_type'],
] : [];
$this->query
->addOrderBy(NULL, NULL, $order, 'price', $params);
}
}
Classes
Name |
Description |
DisplayPrice |
Field handler to provide formatted display prices. |