uc_shipping_handler_field_package_weight.inc 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * @file
  4. * Total package weight field handler.
  5. */
  6. /**
  7. * Field handler: displays the weight of the package.
  8. *
  9. * We cannot use a subquery because there is no way to make sure that all products
  10. * in packages have the same weight unit.
  11. */
  12. class uc_shipping_handler_field_package_weight extends uc_product_handler_field_weight {
  13. /**
  14. * Overrides views_handler::use_group_by().
  15. *
  16. * Disables aggregation for this field.
  17. */
  18. function use_group_by() {
  19. return FALSE;
  20. }
  21. /**
  22. * Overrides uc_product_handler_field_weight::query().
  23. */
  24. function query() {
  25. $this->ensure_my_table();
  26. $this->add_additional_fields();
  27. }
  28. /**
  29. * Overrides uc_product_handler_field_weight::render().
  30. */
  31. function render($values) {
  32. $package = uc_shipping_package_load($values->{$this->aliases['package_id']});
  33. if ($this->options['format'] == 'numeric') {
  34. return $package->weight;
  35. }
  36. if ($this->options['format'] == 'uc_weight') {
  37. return uc_weight_format($package->weight, $package->weight_units);
  38. }
  39. }
  40. }