Get Tier price by SKU or Product id in Magento 2 with TierPrice Storage Interface.
Magento\Catalog\Api\TierPriceStorageInterface is used to retrieve the tier price of a product. get(array $sku) method with an array of product SKU as an argument returns pricing information for the specified product.
You can retrieve the tier price of a single product or multiple products by their SKU as comma-separated. Just refer to the code snippet to get the tier price,
<?php namespace Jesadiya\TierPrice\Model; use Magento\Catalog\Api\Data\TierPriceInterface; use Magento\Catalog\Api\TierPriceStorageInterface; use Psr\Log\LoggerInterface; class GetTierPrice { public function __construct( private TierPriceStorageInterface $tierPrice, private LoggerInterface $logger ) { } /** * tier price result * * @param array $sku * @return TierPriceInterface[] */ public function getTierPrice(array $sku): array { $result = []; try { $result = $this->tierPrice->get($sku); } catch (\Exception $exception) { $this->logger->error($exception->getMessage()); } return $result; } }
Call method with an array of SKUs,
$sku = ['24-MB01'];
$result = $this->getTierPrice($sku);
if (count($result)) {
foreach ($result as $item) {
var_dump($item->getData())
}
}
The Result will be price type, customer_group, qty, and amount of discount value as price.
Output:
Array ( [price] => 15.0000 [price_type] => discount [website_id] => 0 [sku] => 24-MB01 [customer_group] => all groups [quantity] => 10.0000 ) ...