Try harder to avoid duplicate order state IDs.
authorIain Patterson <me@iain.cx>
Thu, 10 Apr 2014 15:27:14 +0000 (11:27 -0400)
committerIain Patterson <me@iain.cx>
Thu, 10 Apr 2014 15:27:14 +0000 (11:27 -0400)
An order whose state was changed from delivered to something else then
back to delivered might still appear in the order state array despite
the presence of the hacked query to filter them out.

We now run a secondary hack to remove them from the array.

A better solution is needed here...

lib/report.php

index b2bc16d..c58864d 100644 (file)
     $sth = $dbh->prepare("select * from OrderState o where updated=(select min(updated) from OrderState where order_id=o.order_id and state & " . $GLOBALS['STATE_DELIVERED'] . ") and updated between '$from' and '$to'");
     $sth->execute();
     $order_states = OrderStatePeer::populateObjects($sth);
+    $dups = array();
     foreach ($order_states as $order_state) {
-      $order_ids[] = $order_state->getOrderId();
-      $order_state_ids[] = $order_state->getId();
+      $order_id = $order_state->getOrderId();
+      $order_ids[] = $order_id;
+      if (! $dups[$order_id]) $order_state_ids[] = $order_state->getId();
+      $dups[$order_id] = true;
     }
     $q = new OrderQuery;
     $q->filterById($order_ids);