Skip to content

Instantly share code, notes, and snippets.

@Rud5G
Created June 5, 2012 18:53
Show Gist options
  • Save Rud5G/2876937 to your computer and use it in GitHub Desktop.
Save Rud5G/2876937 to your computer and use it in GitHub Desktop.
snippet: colinmollenhour/adding-minimal-price-to-any-product-collection-in-magento
<?php
/**
* @see http://colin.mollenhour.com/2009/06/04/adding-minimal-price-to-any-product-collection-in-magento/
*/
/*
* example product collection:
* $_products = Mage::getResourceModel('catalog/product_collection')->setStoreId($storeId);
*/
$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']);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment