Adding Minimal Price To Any Product Collection in Magento
There are many “Bestseller“, “Most Viewed”, and other front-page modules available for Magento. Those that use the Reports module to maintain good performance have the slight drawback that they do not inherit the catalog/product_collection resource model and it’s handy addMinimalPrices() function. This function adds the fields necessary for the getPriceHtml($product, TRUE) function to work, which prints out the “As low as” text for products that have tiered pricing. This is a must-have feature if you use tiered pricing, so here is how you can make getPriceHTML($product, TRUE) work with any collection of products:
$productIds = array_keys($_products->getItems());
$minimalPriceModel = Mage::getResourceModel('catalogindex/price');
$minimalPriceModel->setStoreId(Mage::app()->getStore()->getId());
$minimalPriceModel->setCustomerGroupId(
Mage::getSingleton('customer/session')->getCustomerGroupId());
$minimalPrices = $minimalPriceModel->getMinimalPrices($productIds);
foreach ($minimalPrices as $row) {
$item = $_products->getItemById($row['entity_id']);
if ($item) {
$item->setData('minimal_price', $row['value']);
$item->setData('minimal_tax_class_id', $row['tax_class_id']);
}
}
There you have it!