You can add/update tier price to the Product from the Admin Panel Manually.
Just Login with Admin Panel, From Left Sidebar by clicking on Products -> Add or Edit Product -> Price (Click on Advanced Pricing).
If you have to task to add tier price in the product programmatically in Magento using add() method from the ScopedProductTierPriceManagementInterface.
Magento Native Method to add tier price programmatically,
public function add($sku, \Magento\Catalog\Api\Data\ProductTierPriceInterface $tierPrice);
$sku is the Product SKU.
$tierPrice is the ProductTierPriceInterface where you need to create ProductTierPriceInterfacefactory with set Qty(float), Price Value(float), and Customer Group id to add tier price.
<?php namespace Jesadiya\AddTierPrice\Model; use Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory; use Magento\Catalog\Api\ScopedProductTierPriceManagementInterface; use Magento\Framework\Exception\CouldNotSaveException; use Magento\Framework\Exception\NoSuchEntityException; class AddUpdateTierPrice { /** * @var ScopedProductTierPriceManagementInterface */ private $tierPrice; /** * @var ProductTierPriceInterfaceFactory */ private $productTierPriceFactory; public function __construct( ScopedProductTierPriceManagementInterface $tierPrice, ProductTierPriceInterfaceFactory $productTierPriceFactory ) { $this->tierPrice = $tierPrice; $this->productTierPriceFactory = $productTierPriceFactory; } /** * Add Tier price to the Product * * @return bool * @throws CouldNotSaveException * @throws NoSuchEntityException */ public function addTierPrice() { $qty = 7.00; // must be float value. $price = 20.00; // must be float value. $customerGroupId = 1; $sku = '24-MB02'; $tierPrice = false; try { $tierPriceData = $this->productTierPriceFactory->create(); $tierPriceData->setCustomerGroupId($customerGroupId) ->setQty($qty) ->setValue($price); $tierPrice = $this->tierPrice->add($sku, $tierPriceData); } catch (NoSuchEntityException $exception) { throw new NoSuchEntityException(__($exception->getMessage())); } return $tierPrice; } }
You can add tier price by call method,
echo $tierPriceData = $this->addTierPrice();
Output:
Boolean