Get Tier price by SKU or Product id in Magento 2 with TierPrice Storage Interface.
Magento\Catalog\Api\TierPriceStorageInterface used to retrieve the tier price of a product. get(array $sku) method with an array of product SKU as argument returns pricing information for the specified product.
You can retrieve the tier price of the single product or multiple products by their SKU as comma-separated. Just refer the code snippet to get tier price,
<?php namespace Jesadiya\TierPrice\Model; use Magento\Catalog\Api\Data\TierPriceInterface; use Magento\Catalog\Api\TierPriceStorageInterface; use Psr\Log\LoggerInterface; class GetTierPrice { /** * @var TierPriceStorageInterface */ private $tierPrice; /** * @var LoggerInterface */ private $logger; public function __construct( TierPriceStorageInterface $tierPrice, LoggerInterface $logger ) { $this->tierPrice = $tierPrice; $this->logger = $logger; } /** * tier price result * * @param array $sku * @return TierPriceInterface[] */ public function getTierPrice(array $sku) { $result = []; try { $result = $this->tierPrice->get($sku); } catch (\Exception $exception) { $this->logger->error($exception->getMessage()); } return $result; } }
Call method with an array of SKU,
$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 ) ...