Created
June 5, 2012 18:53
-
-
Save Rud5G/2876937 to your computer and use it in GitHub Desktop.
snippet: colinmollenhour/adding-minimal-price-to-any-product-collection-in-magento
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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