uc_coupon_handler_field_all_orders_gross.inc 1002 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. // $Id$
  3. /**
  4. * @file
  5. * Coupon order total field handler
  6. */
  7. class uc_coupon_handler_field_all_orders_gross extends uc_coupon_handler_field_all_orders_total {
  8. /**
  9. * Add the aggregate field that will sum total+value
  10. *
  11. */
  12. function query() {
  13. $this->ensure_my_table();
  14. $uco = $this->query->ensure_table('uc_coupons_orders');
  15. $uo = $this->query->ensure_table('uc_orders');
  16. $this->add_additional_fields();
  17. if (empty($this->options['statuses'])) {
  18. // If no status specified, then we show all.
  19. $in_status = "1";
  20. }
  21. else {
  22. // An array of statuses was specified.
  23. $in_status = "$uo.order_status IN('" . implode("', '", $this->options['statuses']) . "')";
  24. }
  25. $this->field_alias = $this->query->add_field(
  26. NULL,
  27. "CASE WHEN $in_status THEN ($uo.order_total+$uco.value) ELSE 0 END",
  28. $this->table_alias . '_' . $this->field . '_' . implode('_', $this->options['statuses']),
  29. array('function' => 'sum')
  30. );
  31. }
  32. }