Magento 2 – How to Get Tier Price of Product

magento2tierprice

How to get tier price of the product in Magento 2 with custom code?

This is my code

 public function getProductCollection()
    {
        $collection = $this->_productCollectionFactory->create();
        $collection->addAttributeToSelect('*');
         $collection->setOrder('created_at', 'DESC');
        // $collection->setPageSize(3); // fetching only 3 products
        return $collection;
    }

and my call function in .phtml

  $productCollection = $block->getProductCollection();
   $productCollection->setPageSize(2);
            foreach ($productCollection as $product) {

 echo $product->getName();
 print_r($product->getTierPrice());

echo getName ,getPrice,getSpecial price works

but getTierPrice is not working.

ex. I have VIP member card (customer_group) I want to show tier price VIP member card to public not set all group
I want to show tier price VIP member card

Best Answer

You can get the TierPrice as below.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product_obj = $objectManager->create('Magento\Catalog\Model\Product')->load(1);                
$tier_price = $product_obj->getTierPrice();
if(count($tier_price) > 0){
    foreach($tier_price as $pirces){
        foreach ( array_reverse($pirces) as $k => $v ) {
            if($k == "price"){
                $tp = number_format($v, 2, '.', '');
                echo $tp;
            }
        }
    }
}

$product_obj have a product data please check or debut it you can know. It will work 100%. see my log pic below.

enter image description here

Create constructor in your class and initiate the class object. From that Object you can do stuff.