title: Get Number of Orders per Product
body: <p>I'm trying to build an array of orders => products that I can use in reporting/updating attributes.  The format I'm going for is:</p>
  
  <pre><code>//$orders[&lt;number of orders&gt;] = &lt;array of product ids with this many orders&gt;
  $orders = array(
      1 =&gt; array(1, 2, 3),
      2 =&gt; array(4, 5)
      //etc
  );
  </code></pre>
  
  <p>So far the best I can do is</p>
  
  <pre><code>$productCollection = Mage::getModel('catalog/product')
      -&gt;addAttributeToSelect("sku")
      -&gt;getCollection();
  
  $orders = array();
  
  foreach ($productCollection as $product) {
  
      $ordered = Mage::getResourceModel('reports/product_collection')
          -&gt;addOrderedQty()
          -&gt;addAttributeToFilter('sku', $product-&gt;getSku())
          -&gt;setOrder('ordered_qty', 'desc')
          -&gt;getFirstItem();
  
      $qtyOrdered = $ordered-&gt;getOrderedQty();
      $total = $this-&gt;_counter - (int)(!$ordered ? 0 : $qtyOrdered);
  
      if (!is_array($orders[$total])) {
  
          $orders[$total] = array();
      }
  
      $orders[$total][] = $product-&gt;getId();
  }
  </code></pre>
  
  <p>But this is obviously using a lot of resources, loading the entire product collection.</p>
  
  <p>I think I can get by just using</p>
  
  <pre><code>$ordered = Mage::getResourceModel('reports/product_collection')
      -&gt;addOrderedQty();
  </code></pre>
  
  <p>But I'm having trouble returning/iterating through the results.  How do I extract the information I'm looking for?</p>