Archive

Archive for June, 2009

Adding Minimal Price To Any Product Collection in Magento

June 4th, 2009

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!

Magento ,

Hiding “Out of Stock” Items in Magento

June 2nd, 2009

Updated 7/14/09

This module has been replaced with one that correctly updates the layered navigation counts. See the new version here.

Updated 7/3/09

The in-stock-only module now works properly when multiple websites are in use.

Updated 6/26/09

The in-stock-only module now works with configurable products.

 

Magento has several criteria for determining if an item should be visible in the store, but one of these is not whether or not the item is in stock. Magento can manage your stock and will set your stock status to “Out of Stock” for you, but what if you want these out of stock items to be hidden from the store.. automatically? Also, in my case I do not want to “disable” the item because the inventory management system will then ignore it. Turns out this was much more difficult to figure out than I expected it to be but the end solution was quite simple.

Read more…

Magento, Programming ,