Get magento grouped product lowest price

Get magento grouped product lowest price

August 29, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Get magento grouped product lowest price

Getting the Lowest Price of a Grouped Magento Product

If you’re trying to fetch the lowest price from a grouped product in Magento, you’ve likely encountered some challenges. This is a common issue that many developers face when working with this platform’s complex product structure.

Understanding Magento’s Grouped Products

In Magento, a grouped product is essentially a virtual product that contains other simple or configurable products. When you create a grouped product, you’re not actually adding inventory; instead, you’re creating a bundle of existing items.

This unique architecture can make it difficult to retrieve the lowest price directly from the grouped product’s collection. The standard approach used in your provided code doesn’t account for the layered pricing structure of these products.

A Better Approach: Retrieving the Lowest Child Product Price

To solve this issue, we need to access the child products associated with the grouped item and find the one with the lowest price. Here’s a corrected version of your code that achieves this:

<?php
$cat_id = 33;
$category_model = Mage::getModel('catalog/category')->load($cat_id);
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->addCategoryFilter($category_model);

foreach ($collection as $_product) {
    if ($_product->getTypeId() == 'grouped') {
        $associated_products = $_product->getTypeInstance()->getAssociatedProducts($_product);
        $lowest_price = PHP_INT_MAX;

        foreach ($associated_products as $_child_product) {
            $price = floatval($_child_product->getPrice());
            if ($price < $lowest_price) {
                $lowest_price = $price;
            }
        }

        echo Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol() . sprintf('%.2f', $lowest_price);
    } else {
        // Handle non-grouped products
    }
}
?>

How This Code Works

This script first filters the product collection by category. It then loops through each product in the collection, checking if it’s a grouped product ($_product->getTypeId() == 'grouped').

If it is, the code uses the grouped product’s type instance to retrieve its associated products ($_product->getTypeInstance()->getAssociatedProducts($_product)). It then initializes a variable $lowest_price with an extremely high number (PHP_INT_MAX) to represent the current lowest price found.

The script subsequently loops through each of the associated child products. For each product, it converts its price to a float and compares it against the current $lowest_price. If the child product’s price is lower, it updates the $lowest_price variable accordingly.

Finally, outside the nested loop, the code prints the lowest price found in the desired currency format using Magento’s locale and currency functions.

Conclusion

Retrieving the lowest price from a grouped Magento product requires a more nuanced approach than simply accessing the parent product’s price. By directly handling the associated child products, we can accurately determine the most affordable option within the group.

Remember that this solution assumes you’re working with simple or configurable child products, not virtual or downloadable ones. The logic would need to be adjusted if your grouped products contain a mix of these types.

For more advanced pricing scenarios involving tiered prices, special prices, or customer group-specific prices, consider using Magento’s price rule system and the getFinalPrice() method for more accurate results.

Don’t hesitate to reach out to our team at Laravel Company if you have any questions about Magento development or need assistance with your e-commerce projects.

Catalog Configuration Customers Pricing

Our network