Skip to content

Instantly share code, notes, and snippets.

@Luxato
Last active January 11, 2021 14:51
Show Gist options
  • Save Luxato/a5c9b8f9adb3518d4dac39f2b9bb2bdf to your computer and use it in GitHub Desktop.
Save Luxato/a5c9b8f9adb3518d4dac39f2b9bb2bdf to your computer and use it in GitHub Desktop.
Magento 1 join collection with table created by subquery
<?php
$productCollection->getSelect()->join(
new Zend_Db_Expr("(SELECT product_id, SUM(impressions) as impressions, SUM(clicks) as clicks, SUM(cart) as cart, SUM(conversions) as conversions, round(SUM(profit), 2) as profit, round(SUM(profit)/SUM(impressions), 3) as rpi
FROM evermart_crosssells_statistics_daily" .
($dateFilter ? " WHERE $dateFilter" : "")
. " GROUP BY product_id)"),
't.product_id = e.entity_id',
array('t.impressions','t.clicks', 't.cart', 't.conversions', 't.profit', 't.rpi')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment