/** * Add price index filter * * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection * * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection */ public function addPriceIndexFilter($collection) { $select = $collection->getSelect(); $fromPart = $select->getPart(Zend_Db_Select::FROM); if (isset($fromPart['price_index'])) { $joinCond = $fromPart['price_index']['joinCondition']; if (strpos($joinCond, 'price_index.store_id') === false) { $helper = $this->getStorePricingHelper(); $connection = $collection->getConnection(); if (!$collection->getFlag('store_id')) { $storeId = $helper->getCurrentStoreId(); } else { $storeId = $collection->getFlag('store_id'); } $storeId = $connection->quote($storeId); if ($storeId) { $joinCond .= " AND (price_index.store_id = {$storeId})"; } else { $joinCond .= " AND (price_index.store_id = 0)"; } $fromPart['price_index']['joinCondition'] = $joinCond; $select->setPart(Zend_Db_Select::FROM, $fromPart); } } return $collection; }