uc_order_handler_field_order_cost.inc 961 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. * @file
  4. * Order total cost field handler.
  5. */
  6. /**
  7. * Field handler: displays the total cost of an order.
  8. */
  9. class uc_order_handler_field_order_cost extends uc_order_handler_field_money_amount {
  10. /**
  11. * Constructor.
  12. */
  13. function construct() {
  14. parent::construct();
  15. $this->additional_fields['order_id'] = 'order_id';
  16. }
  17. /**
  18. * Overrides views_handler_field::query().
  19. */
  20. function query() {
  21. $this->ensure_my_table();
  22. $this->add_additional_fields();
  23. // Do nothing else with the query, we'll be retrieving the information directly.
  24. }
  25. /**
  26. * Overrides views_handler_field::render().
  27. */
  28. function render($values) {
  29. $this->field_alias = 'order_cost';
  30. $cost = db_query("SELECT SUM(cost * qty) FROM {uc_order_products} WHERE order_id = :oid", array(':oid' => $values->{$this->aliases['order_id']}))->fetchField();
  31. $values->{$this->field_alias} = $cost;
  32. return parent::render($values);
  33. }
  34. }