Skip to content

Magento2 – Get the lowest tier price from associated products

I am trying to extract the lowest tier price from the associated products of a configurable.

For example, I have a configurable product of a usb stick and the tier price of its associated products increases with memory type. This is the code I have done for now but it only extracts the tier price of the first associated product it casually finds in the foreach:

<?php 
                        
                        if($_product->getTypeId() == "configurable"){
                            $simple_collection = $_product->getTypeInstance()->getUsedProducts($_product); 
                            
                            foreach($simple_collection as $simple_product){$tier_price = $simple_product->getTierPrice();break;}
                            
                        } else {
                            $tier_price = $blockProduct->getProductById($_product->getId())->getTierPrice();
                        }
                        
                            $tier_price_end = end($tier_price);
                            
                            echo number_format($tier_price_end["price"],2);
                            
                        ?>

How can I find the lowest tier price by checking all associated products without having to use foreach?