How to get configurable product price range in magento?

How to get configurable product price range in magento?

July 5, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to get configurable product price range in magento?

Configuring Product Price Range in Magento: A Comprehensive Guide

In Magento, configuring a product’s price range requires understanding how prices are stored for different customer groups and tiers. Let me guide you through the process of getting the minimum and maximum values for both regular and special (configured) prices.

Understanding Magento’s Price Management System

Magento stores multiple prices per product to accommodate various pricing strategies like tiered pricing, group pricing, and special pricing. These are stored in the catalog_product_index_price table.

Getting Configured Product Prices

To get the configured price range for a logged-in customer:

  1. Check if a customer is logged in.
  2. Retrieve the customer’s group ID.
  3. Create a database query to fetch the minimum and maximum prices from the catalog_product_index_price table.

Here’s an improved version of your existing code with error handling and proper variable naming:

try {
    if (Mage::getSingleton('customer/session')->isLoggedIn()) {
        $groupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
    } else {
        $groupId = 0;
    }

    $resource = Mage::getSingleton('core/resource');
    $readConnection = $resource->getConnection('core_read');

    // Prepare the SQL query
    $select = $readConnection->select()
        ->from(['p' => 'catalog_product_index_price'])
        ->where('p.entity_id = ?', $_product->getId())
        ->where('p.customer_group_id = ?', $groupId)
        ->order('p.customer_group_id ASC')
        ->limit(1);

    // Execute the query
    $specialPrices = $readConnection->fetchAll($select);

    if (!empty($specialPrices)) {
        $minSpecialPrice = min(array_column($specialPrices, 'price'));
        $maxSpecialPrice = max(array_column($specialPrices, 'final_price'));

        // You can now use $minSpecialPrice and $maxSpecialPrice in your template
        Mage::log('Minimum special price: ' . $minSpecialPrice);
        Mage::log('Maximum special price: ' . $maxSpecialPrice);
    }
} catch (Exception $e) {
    Mage::logException($e);
}

Getting Regular Price Range

To get the minimum and maximum regular prices:

  1. Use the catalog_product_index_price table again, but this time without any customer group filter.
  2. Select all available prices for the product.

Here’s how to fetch the regular price range:

try {
    $regularPrices = $readConnection->fetchAll($selectWithoutGroupFilter);

    if (!empty($regularPrices)) {
        $minRegularPrice = min(array_column($regularPrices, 'price'));
        $maxRegularPrice = max(array_column($regularPrices, 'final_price'));

        Mage::log('Minimum regular price: ' . $minRegularPrice);
        Mage::log('Maximum regular price: ' . $maxRegularPrice);
    }
} catch (Exception $e) {
    Mage::logException($e);
}

Displaying the Price Range in Your Template

In your template file, you can now display the configured and regular price ranges like this:

<?php if ($minSpecialPrice && $maxSpecialPrice): ?>
  <div class="price-range">
    Configured Price: <?php echo Mage::helper('core')->currency($minSpecialPrice, true, false) ?> - <?php echo Mage::helper('core')->currency($maxSpecialPrice, true, false) ?>
  </div>
<?php endif; ?>

<?php if ($minRegularPrice && $maxRegularPrice): ?>
  <div class="price-range">
    Regular Price: <?php echo Mage::helper('core')->currency($minRegularPrice, true, false) ?> - <?php echo Mage::helper('core')->currency($maxRegularPrice, true, false) ?>
  </div>
<?php endif; ?>

Conclusion

To summarize, you can get the configured and regular price ranges for a Magento product by querying the catalog_product_index_price table based on the logged-in customer’s group ID or without any filter for regular prices.

Remember to handle potential errors gracefully and log exceptions using Magento’s built-in logging system. This approach ensures that your store remains stable even if something goes wrong during price retrieval.

If you’re looking to optimize performance, consider implementing a caching strategy or using price indexers to reduce database load. For more advanced pricing configurations and strategies, I recommend exploring Laravel Company’s Magento development services. Our expert team can help you implement complex pricing rules and ensure your store is optimized for performance.

Happy coding!

Catalog Database Configuration Customers

Our network