Is the Lenspen Panamatic of any real use for creating panoramic shots or is it a waste of money?

More product details


Question: Magento aggregate and between collections?
Answer: Assuming you have a model mapped to your table1 and one mapped to table2 you can try something like this.

$date = '2014-07-08';
$collection = Mage::getModel('[module]/table1')-&gt;getCollection()
    -&gt;addFieldToFilter('active', 0)
    -&gt;addFieldToFilter('not_available_from_date', array('date' =&gt; true, 'to' =&gt; $date))
    -&gt;addFieldToFilter('not_available_to_date', array('date' =&gt; true, 'from' =&gt; $date));


And for the second one.

$collection = Mage::getModel('[module]/table2')-&gt;getCollection()
    -&gt;addExpressionFieldToSelect('total', 'SUM({{qty}} + {{product_id}} - {{any_other_columns}})', array('{{qty}}'=&gt;'qty', '{{product_id}}'=&gt;'product_id', '{{any_other_columns}}'=&gt;'any_other_columns'));
//since SUM requires a GROUP BY...group by some column
$collection-&gt;getSelect()-&gt;group('product_id');


The examples above are for flat entities. 

If you have an EAV entity similar to products or categories use 

addAttributeToFilter instead of addFieldToFilter 

addExpressionAttributeToSelect instead of addExpressionFieldToSelect

EDIT

After an other investigation I found that for flat entities you can use directly the column names. The attribute placeholders {{...}} are needed only for EAV entities.  

So your second collection should look like this:

$collection = Mage::getModel('[module]/table2')-&gt;getCollection()
    -&gt;addExpressionFieldToSelect('total', 'SUM(qty + product_id - any_other_columns)', array('qty', 'product_id', 'any_other_columns'));
$collection-&gt;getSelect()-&gt;group('product_id');


The third parameter for addExpressionFieldToSelect is required but it can be an empty array. for addExpressionAttributeToSelect that last parameter should contain the mapping between the placeholders and the attribute codes. In this case seams that they are useless. I don't know if this is a bug or a feature.