title: Magento ordering collections after adding items
body: <p>i have this method on which i retrieve first a Varien_Data_Collection and then I add items one by one from another Varien_Data_Collection by addItem():</p>
  
  <pre><code>    protected function _prepareCollection(){
  
      $productId = $this-&gt;getRequest()-&gt;getParam('id');
      $websiteId = 0;
      if ($store = $this-&gt;getRequest()-&gt;getParam('store')) {
          $websiteId = Mage::app()-&gt;getStore($store)-&gt;getWebsiteId();
  
          $collection = Mage::getModel('productalert/stock')
                  -&gt;getCustomerCollection()
                  -&gt;join($productId, $websiteId); 
  
          foreach ($collection as $item) {
              $item-&gt;setData('is_customer', 'Sì');
          }
  
  
          $guestCollection = Mage::getModel('productsalert/gueststock')-&gt;getCollection()
                  -&gt;addFieldToFilter("product_id", $productId)
                  -&gt;addFieldToFilter("website_id", $websiteId);
  
  
          foreach ($guestCollection as $guestItem) {
              $obj = new Mage_Customer_Model_Customer();
              $obj-&gt;setData($guestItem-&gt;getData());
              $obj-&gt;setData('alert_stock_id', ($guestItem-&gt;getData('alert_stock_id')+100000000));
              $obj-&gt;setData('email', $guestItem-&gt;getData('guest_email'));
              $obj-&gt;setData('is_customer', 'No');
              $collection-&gt;addItem($obj);
          }
          $collection = $collection-&gt;setOrder('add_date','ASC');
          $this-&gt;_sortCollectionDescByDate($collection);
          $this-&gt;setCollection($collection);
      }
      else{
          $this-&gt;setCollection(new Varien_Data_Collection());
      }
  
  
  
  
      return parent::_prepareCollection();
  
  }   
  </code></pre>
  
  <p>So when i have the final collection i want to set the order since items in it have one attribute in common ('add_date'), so i set the setOrder methos, but it doesn't work (soemone on IRC told me that setOrder modify the query). so I can do it manually but it seems strange to me that there's not to order a collection after adding items. i took a look on Varien_Data_Collection API but I don't see anything that could help me. I've also tried to change the collection class to Varien_Data_Collection_Db and setting the addOrder() method but nothing has changed.</p>
  
  <p>any idea?</p>
  
  <p>thanks!</p>
  
  <p>Luke </p>